i40e_common.c 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2015 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include "i40e_type.h"
  27. #include "i40e_adminq.h"
  28. #include "i40e_prototype.h"
  29. #include "i40e_virtchnl.h"
  30. /**
  31. * i40e_set_mac_type - Sets MAC type
  32. * @hw: pointer to the HW structure
  33. *
  34. * This function sets the mac type of the adapter based on the
  35. * vendor ID and device ID stored in the hw structure.
  36. **/
  37. static i40e_status i40e_set_mac_type(struct i40e_hw *hw)
  38. {
  39. i40e_status status = 0;
  40. if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
  41. switch (hw->device_id) {
  42. case I40E_DEV_ID_SFP_XL710:
  43. case I40E_DEV_ID_QEMU:
  44. case I40E_DEV_ID_KX_A:
  45. case I40E_DEV_ID_KX_B:
  46. case I40E_DEV_ID_KX_C:
  47. case I40E_DEV_ID_QSFP_A:
  48. case I40E_DEV_ID_QSFP_B:
  49. case I40E_DEV_ID_QSFP_C:
  50. case I40E_DEV_ID_10G_BASE_T:
  51. hw->mac.type = I40E_MAC_XL710;
  52. break;
  53. case I40E_DEV_ID_VF:
  54. case I40E_DEV_ID_VF_HV:
  55. hw->mac.type = I40E_MAC_VF;
  56. break;
  57. default:
  58. hw->mac.type = I40E_MAC_GENERIC;
  59. break;
  60. }
  61. } else {
  62. status = I40E_ERR_DEVICE_NOT_SUPPORTED;
  63. }
  64. hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
  65. hw->mac.type, status);
  66. return status;
  67. }
  68. /**
  69. * i40e_debug_aq
  70. * @hw: debug mask related to admin queue
  71. * @mask: debug mask
  72. * @desc: pointer to admin queue descriptor
  73. * @buffer: pointer to command buffer
  74. * @buf_len: max length of buffer
  75. *
  76. * Dumps debug log about adminq command with descriptor contents.
  77. **/
  78. void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
  79. void *buffer, u16 buf_len)
  80. {
  81. struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
  82. u16 len = le16_to_cpu(aq_desc->datalen);
  83. u8 *aq_buffer = (u8 *)buffer;
  84. u32 data[4];
  85. u32 i = 0;
  86. if ((!(mask & hw->debug_mask)) || (desc == NULL))
  87. return;
  88. i40e_debug(hw, mask,
  89. "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
  90. le16_to_cpu(aq_desc->opcode),
  91. le16_to_cpu(aq_desc->flags),
  92. le16_to_cpu(aq_desc->datalen),
  93. le16_to_cpu(aq_desc->retval));
  94. i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
  95. le32_to_cpu(aq_desc->cookie_high),
  96. le32_to_cpu(aq_desc->cookie_low));
  97. i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
  98. le32_to_cpu(aq_desc->params.internal.param0),
  99. le32_to_cpu(aq_desc->params.internal.param1));
  100. i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
  101. le32_to_cpu(aq_desc->params.external.addr_high),
  102. le32_to_cpu(aq_desc->params.external.addr_low));
  103. if ((buffer != NULL) && (aq_desc->datalen != 0)) {
  104. memset(data, 0, sizeof(data));
  105. i40e_debug(hw, mask, "AQ CMD Buffer:\n");
  106. if (buf_len < len)
  107. len = buf_len;
  108. for (i = 0; i < len; i++) {
  109. data[((i % 16) / 4)] |=
  110. ((u32)aq_buffer[i]) << (8 * (i % 4));
  111. if ((i % 16) == 15) {
  112. i40e_debug(hw, mask,
  113. "\t0x%04X %08X %08X %08X %08X\n",
  114. i - 15, le32_to_cpu(data[0]),
  115. le32_to_cpu(data[1]),
  116. le32_to_cpu(data[2]),
  117. le32_to_cpu(data[3]));
  118. memset(data, 0, sizeof(data));
  119. }
  120. }
  121. if ((i % 16) != 0)
  122. i40e_debug(hw, mask, "\t0x%04X %08X %08X %08X %08X\n",
  123. i - (i % 16), le32_to_cpu(data[0]),
  124. le32_to_cpu(data[1]),
  125. le32_to_cpu(data[2]),
  126. le32_to_cpu(data[3]));
  127. }
  128. }
  129. /**
  130. * i40e_check_asq_alive
  131. * @hw: pointer to the hw struct
  132. *
  133. * Returns true if Queue is enabled else false.
  134. **/
  135. bool i40e_check_asq_alive(struct i40e_hw *hw)
  136. {
  137. if (hw->aq.asq.len)
  138. return !!(rd32(hw, hw->aq.asq.len) &
  139. I40E_PF_ATQLEN_ATQENABLE_MASK);
  140. else
  141. return false;
  142. }
  143. /**
  144. * i40e_aq_queue_shutdown
  145. * @hw: pointer to the hw struct
  146. * @unloading: is the driver unloading itself
  147. *
  148. * Tell the Firmware that we're shutting down the AdminQ and whether
  149. * or not the driver is unloading as well.
  150. **/
  151. i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
  152. bool unloading)
  153. {
  154. struct i40e_aq_desc desc;
  155. struct i40e_aqc_queue_shutdown *cmd =
  156. (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
  157. i40e_status status;
  158. i40e_fill_default_direct_cmd_desc(&desc,
  159. i40e_aqc_opc_queue_shutdown);
  160. if (unloading)
  161. cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
  162. status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
  163. return status;
  164. }
  165. /* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
  166. * hardware to a bit-field that can be used by SW to more easily determine the
  167. * packet type.
  168. *
  169. * Macros are used to shorten the table lines and make this table human
  170. * readable.
  171. *
  172. * We store the PTYPE in the top byte of the bit field - this is just so that
  173. * we can check that the table doesn't have a row missing, as the index into
  174. * the table should be the PTYPE.
  175. *
  176. * Typical work flow:
  177. *
  178. * IF NOT i40e_ptype_lookup[ptype].known
  179. * THEN
  180. * Packet is unknown
  181. * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
  182. * Use the rest of the fields to look at the tunnels, inner protocols, etc
  183. * ELSE
  184. * Use the enum i40e_rx_l2_ptype to decode the packet type
  185. * ENDIF
  186. */
  187. /* macro to make the table lines short */
  188. #define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
  189. { PTYPE, \
  190. 1, \
  191. I40E_RX_PTYPE_OUTER_##OUTER_IP, \
  192. I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
  193. I40E_RX_PTYPE_##OUTER_FRAG, \
  194. I40E_RX_PTYPE_TUNNEL_##T, \
  195. I40E_RX_PTYPE_TUNNEL_END_##TE, \
  196. I40E_RX_PTYPE_##TEF, \
  197. I40E_RX_PTYPE_INNER_PROT_##I, \
  198. I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
  199. #define I40E_PTT_UNUSED_ENTRY(PTYPE) \
  200. { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  201. /* shorter macros makes the table fit but are terse */
  202. #define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
  203. #define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
  204. #define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
  205. /* Lookup table mapping the HW PTYPE to the bit field for decoding */
  206. struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
  207. /* L2 Packet types */
  208. I40E_PTT_UNUSED_ENTRY(0),
  209. I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  210. I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
  211. I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  212. I40E_PTT_UNUSED_ENTRY(4),
  213. I40E_PTT_UNUSED_ENTRY(5),
  214. I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  215. I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  216. I40E_PTT_UNUSED_ENTRY(8),
  217. I40E_PTT_UNUSED_ENTRY(9),
  218. I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  219. I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
  220. I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  221. I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  222. I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  223. I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  224. I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  225. I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  226. I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  227. I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  228. I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  229. I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  230. /* Non Tunneled IPv4 */
  231. I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
  232. I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
  233. I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
  234. I40E_PTT_UNUSED_ENTRY(25),
  235. I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
  236. I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
  237. I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
  238. /* IPv4 --> IPv4 */
  239. I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  240. I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  241. I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  242. I40E_PTT_UNUSED_ENTRY(32),
  243. I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  244. I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  245. I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  246. /* IPv4 --> IPv6 */
  247. I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  248. I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  249. I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  250. I40E_PTT_UNUSED_ENTRY(39),
  251. I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  252. I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  253. I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  254. /* IPv4 --> GRE/NAT */
  255. I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  256. /* IPv4 --> GRE/NAT --> IPv4 */
  257. I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  258. I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  259. I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  260. I40E_PTT_UNUSED_ENTRY(47),
  261. I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  262. I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  263. I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  264. /* IPv4 --> GRE/NAT --> IPv6 */
  265. I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  266. I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  267. I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  268. I40E_PTT_UNUSED_ENTRY(54),
  269. I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  270. I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  271. I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  272. /* IPv4 --> GRE/NAT --> MAC */
  273. I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  274. /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
  275. I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  276. I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  277. I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  278. I40E_PTT_UNUSED_ENTRY(62),
  279. I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  280. I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  281. I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  282. /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
  283. I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  284. I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  285. I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  286. I40E_PTT_UNUSED_ENTRY(69),
  287. I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  288. I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  289. I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  290. /* IPv4 --> GRE/NAT --> MAC/VLAN */
  291. I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  292. /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
  293. I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  294. I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  295. I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  296. I40E_PTT_UNUSED_ENTRY(77),
  297. I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  298. I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  299. I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  300. /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
  301. I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  302. I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  303. I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  304. I40E_PTT_UNUSED_ENTRY(84),
  305. I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  306. I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  307. I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  308. /* Non Tunneled IPv6 */
  309. I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
  310. I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
  311. I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY3),
  312. I40E_PTT_UNUSED_ENTRY(91),
  313. I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
  314. I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
  315. I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
  316. /* IPv6 --> IPv4 */
  317. I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  318. I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  319. I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  320. I40E_PTT_UNUSED_ENTRY(98),
  321. I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  322. I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  323. I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  324. /* IPv6 --> IPv6 */
  325. I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  326. I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  327. I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  328. I40E_PTT_UNUSED_ENTRY(105),
  329. I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  330. I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  331. I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  332. /* IPv6 --> GRE/NAT */
  333. I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  334. /* IPv6 --> GRE/NAT -> IPv4 */
  335. I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  336. I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  337. I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  338. I40E_PTT_UNUSED_ENTRY(113),
  339. I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  340. I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  341. I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  342. /* IPv6 --> GRE/NAT -> IPv6 */
  343. I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  344. I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  345. I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  346. I40E_PTT_UNUSED_ENTRY(120),
  347. I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  348. I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  349. I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  350. /* IPv6 --> GRE/NAT -> MAC */
  351. I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  352. /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
  353. I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  354. I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  355. I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  356. I40E_PTT_UNUSED_ENTRY(128),
  357. I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  358. I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  359. I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  360. /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
  361. I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  362. I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  363. I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  364. I40E_PTT_UNUSED_ENTRY(135),
  365. I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  366. I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  367. I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  368. /* IPv6 --> GRE/NAT -> MAC/VLAN */
  369. I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  370. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
  371. I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  372. I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  373. I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  374. I40E_PTT_UNUSED_ENTRY(143),
  375. I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  376. I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  377. I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  378. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
  379. I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  380. I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  381. I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  382. I40E_PTT_UNUSED_ENTRY(150),
  383. I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  384. I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  385. I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  386. /* unused entries */
  387. I40E_PTT_UNUSED_ENTRY(154),
  388. I40E_PTT_UNUSED_ENTRY(155),
  389. I40E_PTT_UNUSED_ENTRY(156),
  390. I40E_PTT_UNUSED_ENTRY(157),
  391. I40E_PTT_UNUSED_ENTRY(158),
  392. I40E_PTT_UNUSED_ENTRY(159),
  393. I40E_PTT_UNUSED_ENTRY(160),
  394. I40E_PTT_UNUSED_ENTRY(161),
  395. I40E_PTT_UNUSED_ENTRY(162),
  396. I40E_PTT_UNUSED_ENTRY(163),
  397. I40E_PTT_UNUSED_ENTRY(164),
  398. I40E_PTT_UNUSED_ENTRY(165),
  399. I40E_PTT_UNUSED_ENTRY(166),
  400. I40E_PTT_UNUSED_ENTRY(167),
  401. I40E_PTT_UNUSED_ENTRY(168),
  402. I40E_PTT_UNUSED_ENTRY(169),
  403. I40E_PTT_UNUSED_ENTRY(170),
  404. I40E_PTT_UNUSED_ENTRY(171),
  405. I40E_PTT_UNUSED_ENTRY(172),
  406. I40E_PTT_UNUSED_ENTRY(173),
  407. I40E_PTT_UNUSED_ENTRY(174),
  408. I40E_PTT_UNUSED_ENTRY(175),
  409. I40E_PTT_UNUSED_ENTRY(176),
  410. I40E_PTT_UNUSED_ENTRY(177),
  411. I40E_PTT_UNUSED_ENTRY(178),
  412. I40E_PTT_UNUSED_ENTRY(179),
  413. I40E_PTT_UNUSED_ENTRY(180),
  414. I40E_PTT_UNUSED_ENTRY(181),
  415. I40E_PTT_UNUSED_ENTRY(182),
  416. I40E_PTT_UNUSED_ENTRY(183),
  417. I40E_PTT_UNUSED_ENTRY(184),
  418. I40E_PTT_UNUSED_ENTRY(185),
  419. I40E_PTT_UNUSED_ENTRY(186),
  420. I40E_PTT_UNUSED_ENTRY(187),
  421. I40E_PTT_UNUSED_ENTRY(188),
  422. I40E_PTT_UNUSED_ENTRY(189),
  423. I40E_PTT_UNUSED_ENTRY(190),
  424. I40E_PTT_UNUSED_ENTRY(191),
  425. I40E_PTT_UNUSED_ENTRY(192),
  426. I40E_PTT_UNUSED_ENTRY(193),
  427. I40E_PTT_UNUSED_ENTRY(194),
  428. I40E_PTT_UNUSED_ENTRY(195),
  429. I40E_PTT_UNUSED_ENTRY(196),
  430. I40E_PTT_UNUSED_ENTRY(197),
  431. I40E_PTT_UNUSED_ENTRY(198),
  432. I40E_PTT_UNUSED_ENTRY(199),
  433. I40E_PTT_UNUSED_ENTRY(200),
  434. I40E_PTT_UNUSED_ENTRY(201),
  435. I40E_PTT_UNUSED_ENTRY(202),
  436. I40E_PTT_UNUSED_ENTRY(203),
  437. I40E_PTT_UNUSED_ENTRY(204),
  438. I40E_PTT_UNUSED_ENTRY(205),
  439. I40E_PTT_UNUSED_ENTRY(206),
  440. I40E_PTT_UNUSED_ENTRY(207),
  441. I40E_PTT_UNUSED_ENTRY(208),
  442. I40E_PTT_UNUSED_ENTRY(209),
  443. I40E_PTT_UNUSED_ENTRY(210),
  444. I40E_PTT_UNUSED_ENTRY(211),
  445. I40E_PTT_UNUSED_ENTRY(212),
  446. I40E_PTT_UNUSED_ENTRY(213),
  447. I40E_PTT_UNUSED_ENTRY(214),
  448. I40E_PTT_UNUSED_ENTRY(215),
  449. I40E_PTT_UNUSED_ENTRY(216),
  450. I40E_PTT_UNUSED_ENTRY(217),
  451. I40E_PTT_UNUSED_ENTRY(218),
  452. I40E_PTT_UNUSED_ENTRY(219),
  453. I40E_PTT_UNUSED_ENTRY(220),
  454. I40E_PTT_UNUSED_ENTRY(221),
  455. I40E_PTT_UNUSED_ENTRY(222),
  456. I40E_PTT_UNUSED_ENTRY(223),
  457. I40E_PTT_UNUSED_ENTRY(224),
  458. I40E_PTT_UNUSED_ENTRY(225),
  459. I40E_PTT_UNUSED_ENTRY(226),
  460. I40E_PTT_UNUSED_ENTRY(227),
  461. I40E_PTT_UNUSED_ENTRY(228),
  462. I40E_PTT_UNUSED_ENTRY(229),
  463. I40E_PTT_UNUSED_ENTRY(230),
  464. I40E_PTT_UNUSED_ENTRY(231),
  465. I40E_PTT_UNUSED_ENTRY(232),
  466. I40E_PTT_UNUSED_ENTRY(233),
  467. I40E_PTT_UNUSED_ENTRY(234),
  468. I40E_PTT_UNUSED_ENTRY(235),
  469. I40E_PTT_UNUSED_ENTRY(236),
  470. I40E_PTT_UNUSED_ENTRY(237),
  471. I40E_PTT_UNUSED_ENTRY(238),
  472. I40E_PTT_UNUSED_ENTRY(239),
  473. I40E_PTT_UNUSED_ENTRY(240),
  474. I40E_PTT_UNUSED_ENTRY(241),
  475. I40E_PTT_UNUSED_ENTRY(242),
  476. I40E_PTT_UNUSED_ENTRY(243),
  477. I40E_PTT_UNUSED_ENTRY(244),
  478. I40E_PTT_UNUSED_ENTRY(245),
  479. I40E_PTT_UNUSED_ENTRY(246),
  480. I40E_PTT_UNUSED_ENTRY(247),
  481. I40E_PTT_UNUSED_ENTRY(248),
  482. I40E_PTT_UNUSED_ENTRY(249),
  483. I40E_PTT_UNUSED_ENTRY(250),
  484. I40E_PTT_UNUSED_ENTRY(251),
  485. I40E_PTT_UNUSED_ENTRY(252),
  486. I40E_PTT_UNUSED_ENTRY(253),
  487. I40E_PTT_UNUSED_ENTRY(254),
  488. I40E_PTT_UNUSED_ENTRY(255)
  489. };
  490. /**
  491. * i40e_init_shared_code - Initialize the shared code
  492. * @hw: pointer to hardware structure
  493. *
  494. * This assigns the MAC type and PHY code and inits the NVM.
  495. * Does not touch the hardware. This function must be called prior to any
  496. * other function in the shared code. The i40e_hw structure should be
  497. * memset to 0 prior to calling this function. The following fields in
  498. * hw structure should be filled in prior to calling this function:
  499. * hw_addr, back, device_id, vendor_id, subsystem_device_id,
  500. * subsystem_vendor_id, and revision_id
  501. **/
  502. i40e_status i40e_init_shared_code(struct i40e_hw *hw)
  503. {
  504. i40e_status status = 0;
  505. u32 port, ari, func_rid;
  506. i40e_set_mac_type(hw);
  507. switch (hw->mac.type) {
  508. case I40E_MAC_XL710:
  509. break;
  510. default:
  511. return I40E_ERR_DEVICE_NOT_SUPPORTED;
  512. }
  513. hw->phy.get_link_info = true;
  514. /* Determine port number and PF number*/
  515. port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
  516. >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
  517. hw->port = (u8)port;
  518. ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
  519. I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
  520. func_rid = rd32(hw, I40E_PF_FUNC_RID);
  521. if (ari)
  522. hw->pf_id = (u8)(func_rid & 0xff);
  523. else
  524. hw->pf_id = (u8)(func_rid & 0x7);
  525. status = i40e_init_nvm(hw);
  526. return status;
  527. }
  528. /**
  529. * i40e_aq_mac_address_read - Retrieve the MAC addresses
  530. * @hw: pointer to the hw struct
  531. * @flags: a return indicator of what addresses were added to the addr store
  532. * @addrs: the requestor's mac addr store
  533. * @cmd_details: pointer to command details structure or NULL
  534. **/
  535. static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
  536. u16 *flags,
  537. struct i40e_aqc_mac_address_read_data *addrs,
  538. struct i40e_asq_cmd_details *cmd_details)
  539. {
  540. struct i40e_aq_desc desc;
  541. struct i40e_aqc_mac_address_read *cmd_data =
  542. (struct i40e_aqc_mac_address_read *)&desc.params.raw;
  543. i40e_status status;
  544. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
  545. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
  546. status = i40e_asq_send_command(hw, &desc, addrs,
  547. sizeof(*addrs), cmd_details);
  548. *flags = le16_to_cpu(cmd_data->command_flags);
  549. return status;
  550. }
  551. /**
  552. * i40e_aq_mac_address_write - Change the MAC addresses
  553. * @hw: pointer to the hw struct
  554. * @flags: indicates which MAC to be written
  555. * @mac_addr: address to write
  556. * @cmd_details: pointer to command details structure or NULL
  557. **/
  558. i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
  559. u16 flags, u8 *mac_addr,
  560. struct i40e_asq_cmd_details *cmd_details)
  561. {
  562. struct i40e_aq_desc desc;
  563. struct i40e_aqc_mac_address_write *cmd_data =
  564. (struct i40e_aqc_mac_address_write *)&desc.params.raw;
  565. i40e_status status;
  566. i40e_fill_default_direct_cmd_desc(&desc,
  567. i40e_aqc_opc_mac_address_write);
  568. cmd_data->command_flags = cpu_to_le16(flags);
  569. cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
  570. cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
  571. ((u32)mac_addr[3] << 16) |
  572. ((u32)mac_addr[4] << 8) |
  573. mac_addr[5]);
  574. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  575. return status;
  576. }
  577. /**
  578. * i40e_get_mac_addr - get MAC address
  579. * @hw: pointer to the HW structure
  580. * @mac_addr: pointer to MAC address
  581. *
  582. * Reads the adapter's MAC address from register
  583. **/
  584. i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
  585. {
  586. struct i40e_aqc_mac_address_read_data addrs;
  587. i40e_status status;
  588. u16 flags = 0;
  589. status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
  590. if (flags & I40E_AQC_LAN_ADDR_VALID)
  591. memcpy(mac_addr, &addrs.pf_lan_mac, sizeof(addrs.pf_lan_mac));
  592. return status;
  593. }
  594. /**
  595. * i40e_get_port_mac_addr - get Port MAC address
  596. * @hw: pointer to the HW structure
  597. * @mac_addr: pointer to Port MAC address
  598. *
  599. * Reads the adapter's Port MAC address
  600. **/
  601. i40e_status i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
  602. {
  603. struct i40e_aqc_mac_address_read_data addrs;
  604. i40e_status status;
  605. u16 flags = 0;
  606. status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
  607. if (status)
  608. return status;
  609. if (flags & I40E_AQC_PORT_ADDR_VALID)
  610. memcpy(mac_addr, &addrs.port_mac, sizeof(addrs.port_mac));
  611. else
  612. status = I40E_ERR_INVALID_MAC_ADDR;
  613. return status;
  614. }
  615. /**
  616. * i40e_pre_tx_queue_cfg - pre tx queue configure
  617. * @hw: pointer to the HW structure
  618. * @queue: target pf queue index
  619. * @enable: state change request
  620. *
  621. * Handles hw requirement to indicate intention to enable
  622. * or disable target queue.
  623. **/
  624. void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
  625. {
  626. u32 abs_queue_idx = hw->func_caps.base_queue + queue;
  627. u32 reg_block = 0;
  628. u32 reg_val;
  629. if (abs_queue_idx >= 128) {
  630. reg_block = abs_queue_idx / 128;
  631. abs_queue_idx %= 128;
  632. }
  633. reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
  634. reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
  635. reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
  636. if (enable)
  637. reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
  638. else
  639. reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
  640. wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
  641. }
  642. #ifdef I40E_FCOE
  643. /**
  644. * i40e_get_san_mac_addr - get SAN MAC address
  645. * @hw: pointer to the HW structure
  646. * @mac_addr: pointer to SAN MAC address
  647. *
  648. * Reads the adapter's SAN MAC address from NVM
  649. **/
  650. i40e_status i40e_get_san_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
  651. {
  652. struct i40e_aqc_mac_address_read_data addrs;
  653. i40e_status status;
  654. u16 flags = 0;
  655. status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
  656. if (status)
  657. return status;
  658. if (flags & I40E_AQC_SAN_ADDR_VALID)
  659. memcpy(mac_addr, &addrs.pf_san_mac, sizeof(addrs.pf_san_mac));
  660. else
  661. status = I40E_ERR_INVALID_MAC_ADDR;
  662. return status;
  663. }
  664. #endif
  665. /**
  666. * i40e_read_pba_string - Reads part number string from EEPROM
  667. * @hw: pointer to hardware structure
  668. * @pba_num: stores the part number string from the EEPROM
  669. * @pba_num_size: part number string buffer length
  670. *
  671. * Reads the part number string from the EEPROM.
  672. **/
  673. i40e_status i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
  674. u32 pba_num_size)
  675. {
  676. i40e_status status = 0;
  677. u16 pba_word = 0;
  678. u16 pba_size = 0;
  679. u16 pba_ptr = 0;
  680. u16 i = 0;
  681. status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
  682. if (status || (pba_word != 0xFAFA)) {
  683. hw_dbg(hw, "Failed to read PBA flags or flag is invalid.\n");
  684. return status;
  685. }
  686. status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
  687. if (status) {
  688. hw_dbg(hw, "Failed to read PBA Block pointer.\n");
  689. return status;
  690. }
  691. status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
  692. if (status) {
  693. hw_dbg(hw, "Failed to read PBA Block size.\n");
  694. return status;
  695. }
  696. /* Subtract one to get PBA word count (PBA Size word is included in
  697. * total size)
  698. */
  699. pba_size--;
  700. if (pba_num_size < (((u32)pba_size * 2) + 1)) {
  701. hw_dbg(hw, "Buffer to small for PBA data.\n");
  702. return I40E_ERR_PARAM;
  703. }
  704. for (i = 0; i < pba_size; i++) {
  705. status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
  706. if (status) {
  707. hw_dbg(hw, "Failed to read PBA Block word %d.\n", i);
  708. return status;
  709. }
  710. pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
  711. pba_num[(i * 2) + 1] = pba_word & 0xFF;
  712. }
  713. pba_num[(pba_size * 2)] = '\0';
  714. return status;
  715. }
  716. /**
  717. * i40e_get_media_type - Gets media type
  718. * @hw: pointer to the hardware structure
  719. **/
  720. static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
  721. {
  722. enum i40e_media_type media;
  723. switch (hw->phy.link_info.phy_type) {
  724. case I40E_PHY_TYPE_10GBASE_SR:
  725. case I40E_PHY_TYPE_10GBASE_LR:
  726. case I40E_PHY_TYPE_1000BASE_SX:
  727. case I40E_PHY_TYPE_1000BASE_LX:
  728. case I40E_PHY_TYPE_40GBASE_SR4:
  729. case I40E_PHY_TYPE_40GBASE_LR4:
  730. media = I40E_MEDIA_TYPE_FIBER;
  731. break;
  732. case I40E_PHY_TYPE_100BASE_TX:
  733. case I40E_PHY_TYPE_1000BASE_T:
  734. case I40E_PHY_TYPE_10GBASE_T:
  735. media = I40E_MEDIA_TYPE_BASET;
  736. break;
  737. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  738. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  739. case I40E_PHY_TYPE_10GBASE_CR1:
  740. case I40E_PHY_TYPE_40GBASE_CR4:
  741. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  742. media = I40E_MEDIA_TYPE_DA;
  743. break;
  744. case I40E_PHY_TYPE_1000BASE_KX:
  745. case I40E_PHY_TYPE_10GBASE_KX4:
  746. case I40E_PHY_TYPE_10GBASE_KR:
  747. case I40E_PHY_TYPE_40GBASE_KR4:
  748. media = I40E_MEDIA_TYPE_BACKPLANE;
  749. break;
  750. case I40E_PHY_TYPE_SGMII:
  751. case I40E_PHY_TYPE_XAUI:
  752. case I40E_PHY_TYPE_XFI:
  753. case I40E_PHY_TYPE_XLAUI:
  754. case I40E_PHY_TYPE_XLPPI:
  755. default:
  756. media = I40E_MEDIA_TYPE_UNKNOWN;
  757. break;
  758. }
  759. return media;
  760. }
  761. #define I40E_PF_RESET_WAIT_COUNT_A0 200
  762. #define I40E_PF_RESET_WAIT_COUNT 110
  763. /**
  764. * i40e_pf_reset - Reset the PF
  765. * @hw: pointer to the hardware structure
  766. *
  767. * Assuming someone else has triggered a global reset,
  768. * assure the global reset is complete and then reset the PF
  769. **/
  770. i40e_status i40e_pf_reset(struct i40e_hw *hw)
  771. {
  772. u32 cnt = 0;
  773. u32 cnt1 = 0;
  774. u32 reg = 0;
  775. u32 grst_del;
  776. /* Poll for Global Reset steady state in case of recent GRST.
  777. * The grst delay value is in 100ms units, and we'll wait a
  778. * couple counts longer to be sure we don't just miss the end.
  779. */
  780. grst_del = rd32(hw, I40E_GLGEN_RSTCTL) & I40E_GLGEN_RSTCTL_GRSTDEL_MASK
  781. >> I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
  782. for (cnt = 0; cnt < grst_del + 2; cnt++) {
  783. reg = rd32(hw, I40E_GLGEN_RSTAT);
  784. if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
  785. break;
  786. msleep(100);
  787. }
  788. if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
  789. hw_dbg(hw, "Global reset polling failed to complete.\n");
  790. return I40E_ERR_RESET_FAILED;
  791. }
  792. /* Now Wait for the FW to be ready */
  793. for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
  794. reg = rd32(hw, I40E_GLNVM_ULD);
  795. reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  796. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
  797. if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  798. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
  799. hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
  800. break;
  801. }
  802. usleep_range(10000, 20000);
  803. }
  804. if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  805. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
  806. hw_dbg(hw, "wait for FW Reset complete timedout\n");
  807. hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
  808. return I40E_ERR_RESET_FAILED;
  809. }
  810. /* If there was a Global Reset in progress when we got here,
  811. * we don't need to do the PF Reset
  812. */
  813. if (!cnt) {
  814. if (hw->revision_id == 0)
  815. cnt = I40E_PF_RESET_WAIT_COUNT_A0;
  816. else
  817. cnt = I40E_PF_RESET_WAIT_COUNT;
  818. reg = rd32(hw, I40E_PFGEN_CTRL);
  819. wr32(hw, I40E_PFGEN_CTRL,
  820. (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
  821. for (; cnt; cnt--) {
  822. reg = rd32(hw, I40E_PFGEN_CTRL);
  823. if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
  824. break;
  825. usleep_range(1000, 2000);
  826. }
  827. if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
  828. hw_dbg(hw, "PF reset polling failed to complete.\n");
  829. return I40E_ERR_RESET_FAILED;
  830. }
  831. }
  832. i40e_clear_pxe_mode(hw);
  833. return 0;
  834. }
  835. /**
  836. * i40e_clear_hw - clear out any left over hw state
  837. * @hw: pointer to the hw struct
  838. *
  839. * Clear queues and interrupts, typically called at init time,
  840. * but after the capabilities have been found so we know how many
  841. * queues and msix vectors have been allocated.
  842. **/
  843. void i40e_clear_hw(struct i40e_hw *hw)
  844. {
  845. u32 num_queues, base_queue;
  846. u32 num_pf_int;
  847. u32 num_vf_int;
  848. u32 num_vfs;
  849. u32 i, j;
  850. u32 val;
  851. u32 eol = 0x7ff;
  852. /* get number of interrupts, queues, and vfs */
  853. val = rd32(hw, I40E_GLPCI_CNF2);
  854. num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
  855. I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
  856. num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
  857. I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
  858. val = rd32(hw, I40E_PFLAN_QALLOC);
  859. base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
  860. I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
  861. j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
  862. I40E_PFLAN_QALLOC_LASTQ_SHIFT;
  863. if (val & I40E_PFLAN_QALLOC_VALID_MASK)
  864. num_queues = (j - base_queue) + 1;
  865. else
  866. num_queues = 0;
  867. val = rd32(hw, I40E_PF_VT_PFALLOC);
  868. i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
  869. I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
  870. j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
  871. I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
  872. if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
  873. num_vfs = (j - i) + 1;
  874. else
  875. num_vfs = 0;
  876. /* stop all the interrupts */
  877. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  878. val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
  879. for (i = 0; i < num_pf_int - 2; i++)
  880. wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
  881. /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
  882. val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  883. wr32(hw, I40E_PFINT_LNKLST0, val);
  884. for (i = 0; i < num_pf_int - 2; i++)
  885. wr32(hw, I40E_PFINT_LNKLSTN(i), val);
  886. val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  887. for (i = 0; i < num_vfs; i++)
  888. wr32(hw, I40E_VPINT_LNKLST0(i), val);
  889. for (i = 0; i < num_vf_int - 2; i++)
  890. wr32(hw, I40E_VPINT_LNKLSTN(i), val);
  891. /* warn the HW of the coming Tx disables */
  892. for (i = 0; i < num_queues; i++) {
  893. u32 abs_queue_idx = base_queue + i;
  894. u32 reg_block = 0;
  895. if (abs_queue_idx >= 128) {
  896. reg_block = abs_queue_idx / 128;
  897. abs_queue_idx %= 128;
  898. }
  899. val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
  900. val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
  901. val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
  902. val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
  903. wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
  904. }
  905. udelay(400);
  906. /* stop all the queues */
  907. for (i = 0; i < num_queues; i++) {
  908. wr32(hw, I40E_QINT_TQCTL(i), 0);
  909. wr32(hw, I40E_QTX_ENA(i), 0);
  910. wr32(hw, I40E_QINT_RQCTL(i), 0);
  911. wr32(hw, I40E_QRX_ENA(i), 0);
  912. }
  913. /* short wait for all queue disables to settle */
  914. udelay(50);
  915. }
  916. /**
  917. * i40e_clear_pxe_mode - clear pxe operations mode
  918. * @hw: pointer to the hw struct
  919. *
  920. * Make sure all PXE mode settings are cleared, including things
  921. * like descriptor fetch/write-back mode.
  922. **/
  923. void i40e_clear_pxe_mode(struct i40e_hw *hw)
  924. {
  925. u32 reg;
  926. if (i40e_check_asq_alive(hw))
  927. i40e_aq_clear_pxe_mode(hw, NULL);
  928. /* Clear single descriptor fetch/write-back mode */
  929. reg = rd32(hw, I40E_GLLAN_RCTL_0);
  930. if (hw->revision_id == 0) {
  931. /* As a work around clear PXE_MODE instead of setting it */
  932. wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
  933. } else {
  934. wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
  935. }
  936. }
  937. /**
  938. * i40e_led_is_mine - helper to find matching led
  939. * @hw: pointer to the hw struct
  940. * @idx: index into GPIO registers
  941. *
  942. * returns: 0 if no match, otherwise the value of the GPIO_CTL register
  943. */
  944. static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
  945. {
  946. u32 gpio_val = 0;
  947. u32 port;
  948. if (!hw->func_caps.led[idx])
  949. return 0;
  950. gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
  951. port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
  952. I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
  953. /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
  954. * if it is not our port then ignore
  955. */
  956. if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
  957. (port != hw->port))
  958. return 0;
  959. return gpio_val;
  960. }
  961. #define I40E_LED0 22
  962. #define I40E_LINK_ACTIVITY 0xC
  963. /**
  964. * i40e_led_get - return current on/off mode
  965. * @hw: pointer to the hw struct
  966. *
  967. * The value returned is the 'mode' field as defined in the
  968. * GPIO register definitions: 0x0 = off, 0xf = on, and other
  969. * values are variations of possible behaviors relating to
  970. * blink, link, and wire.
  971. **/
  972. u32 i40e_led_get(struct i40e_hw *hw)
  973. {
  974. u32 mode = 0;
  975. int i;
  976. /* as per the documentation GPIO 22-29 are the LED
  977. * GPIO pins named LED0..LED7
  978. */
  979. for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
  980. u32 gpio_val = i40e_led_is_mine(hw, i);
  981. if (!gpio_val)
  982. continue;
  983. mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
  984. I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
  985. break;
  986. }
  987. return mode;
  988. }
  989. /**
  990. * i40e_led_set - set new on/off mode
  991. * @hw: pointer to the hw struct
  992. * @mode: 0=off, 0xf=on (else see manual for mode details)
  993. * @blink: true if the LED should blink when on, false if steady
  994. *
  995. * if this function is used to turn on the blink it should
  996. * be used to disable the blink when restoring the original state.
  997. **/
  998. void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
  999. {
  1000. int i;
  1001. if (mode & 0xfffffff0)
  1002. hw_dbg(hw, "invalid mode passed in %X\n", mode);
  1003. /* as per the documentation GPIO 22-29 are the LED
  1004. * GPIO pins named LED0..LED7
  1005. */
  1006. for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
  1007. u32 gpio_val = i40e_led_is_mine(hw, i);
  1008. if (!gpio_val)
  1009. continue;
  1010. gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
  1011. /* this & is a bit of paranoia, but serves as a range check */
  1012. gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
  1013. I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
  1014. if (mode == I40E_LINK_ACTIVITY)
  1015. blink = false;
  1016. if (blink)
  1017. gpio_val |= (1 << I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
  1018. else
  1019. gpio_val &= ~(1 << I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
  1020. wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
  1021. break;
  1022. }
  1023. }
  1024. /* Admin command wrappers */
  1025. /**
  1026. * i40e_aq_get_phy_capabilities
  1027. * @hw: pointer to the hw struct
  1028. * @abilities: structure for PHY capabilities to be filled
  1029. * @qualified_modules: report Qualified Modules
  1030. * @report_init: report init capabilities (active are default)
  1031. * @cmd_details: pointer to command details structure or NULL
  1032. *
  1033. * Returns the various PHY abilities supported on the Port.
  1034. **/
  1035. i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
  1036. bool qualified_modules, bool report_init,
  1037. struct i40e_aq_get_phy_abilities_resp *abilities,
  1038. struct i40e_asq_cmd_details *cmd_details)
  1039. {
  1040. struct i40e_aq_desc desc;
  1041. i40e_status status;
  1042. u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
  1043. if (!abilities)
  1044. return I40E_ERR_PARAM;
  1045. i40e_fill_default_direct_cmd_desc(&desc,
  1046. i40e_aqc_opc_get_phy_abilities);
  1047. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1048. if (abilities_size > I40E_AQ_LARGE_BUF)
  1049. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1050. if (qualified_modules)
  1051. desc.params.external.param0 |=
  1052. cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
  1053. if (report_init)
  1054. desc.params.external.param0 |=
  1055. cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
  1056. status = i40e_asq_send_command(hw, &desc, abilities, abilities_size,
  1057. cmd_details);
  1058. if (hw->aq.asq_last_status == I40E_AQ_RC_EIO)
  1059. status = I40E_ERR_UNKNOWN_PHY;
  1060. return status;
  1061. }
  1062. /**
  1063. * i40e_aq_set_phy_config
  1064. * @hw: pointer to the hw struct
  1065. * @config: structure with PHY configuration to be set
  1066. * @cmd_details: pointer to command details structure or NULL
  1067. *
  1068. * Set the various PHY configuration parameters
  1069. * supported on the Port.One or more of the Set PHY config parameters may be
  1070. * ignored in an MFP mode as the PF may not have the privilege to set some
  1071. * of the PHY Config parameters. This status will be indicated by the
  1072. * command response.
  1073. **/
  1074. enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
  1075. struct i40e_aq_set_phy_config *config,
  1076. struct i40e_asq_cmd_details *cmd_details)
  1077. {
  1078. struct i40e_aq_desc desc;
  1079. struct i40e_aq_set_phy_config *cmd =
  1080. (struct i40e_aq_set_phy_config *)&desc.params.raw;
  1081. enum i40e_status_code status;
  1082. if (!config)
  1083. return I40E_ERR_PARAM;
  1084. i40e_fill_default_direct_cmd_desc(&desc,
  1085. i40e_aqc_opc_set_phy_config);
  1086. *cmd = *config;
  1087. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1088. return status;
  1089. }
  1090. /**
  1091. * i40e_set_fc
  1092. * @hw: pointer to the hw struct
  1093. *
  1094. * Set the requested flow control mode using set_phy_config.
  1095. **/
  1096. enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
  1097. bool atomic_restart)
  1098. {
  1099. enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
  1100. struct i40e_aq_get_phy_abilities_resp abilities;
  1101. struct i40e_aq_set_phy_config config;
  1102. enum i40e_status_code status;
  1103. u8 pause_mask = 0x0;
  1104. *aq_failures = 0x0;
  1105. switch (fc_mode) {
  1106. case I40E_FC_FULL:
  1107. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
  1108. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
  1109. break;
  1110. case I40E_FC_RX_PAUSE:
  1111. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
  1112. break;
  1113. case I40E_FC_TX_PAUSE:
  1114. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
  1115. break;
  1116. default:
  1117. break;
  1118. }
  1119. /* Get the current phy config */
  1120. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  1121. NULL);
  1122. if (status) {
  1123. *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
  1124. return status;
  1125. }
  1126. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  1127. /* clear the old pause settings */
  1128. config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
  1129. ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
  1130. /* set the new abilities */
  1131. config.abilities |= pause_mask;
  1132. /* If the abilities have changed, then set the new config */
  1133. if (config.abilities != abilities.abilities) {
  1134. /* Auto restart link so settings take effect */
  1135. if (atomic_restart)
  1136. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  1137. /* Copy over all the old settings */
  1138. config.phy_type = abilities.phy_type;
  1139. config.link_speed = abilities.link_speed;
  1140. config.eee_capability = abilities.eee_capability;
  1141. config.eeer = abilities.eeer_val;
  1142. config.low_power_ctrl = abilities.d3_lpan;
  1143. status = i40e_aq_set_phy_config(hw, &config, NULL);
  1144. if (status)
  1145. *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
  1146. }
  1147. /* Update the link info */
  1148. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  1149. if (status) {
  1150. /* Wait a little bit (on 40G cards it sometimes takes a really
  1151. * long time for link to come back from the atomic reset)
  1152. * and try once more
  1153. */
  1154. msleep(1000);
  1155. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  1156. }
  1157. if (status)
  1158. *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
  1159. return status;
  1160. }
  1161. /**
  1162. * i40e_aq_clear_pxe_mode
  1163. * @hw: pointer to the hw struct
  1164. * @cmd_details: pointer to command details structure or NULL
  1165. *
  1166. * Tell the firmware that the driver is taking over from PXE
  1167. **/
  1168. i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
  1169. struct i40e_asq_cmd_details *cmd_details)
  1170. {
  1171. i40e_status status;
  1172. struct i40e_aq_desc desc;
  1173. struct i40e_aqc_clear_pxe *cmd =
  1174. (struct i40e_aqc_clear_pxe *)&desc.params.raw;
  1175. i40e_fill_default_direct_cmd_desc(&desc,
  1176. i40e_aqc_opc_clear_pxe_mode);
  1177. cmd->rx_cnt = 0x2;
  1178. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1179. wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
  1180. return status;
  1181. }
  1182. /**
  1183. * i40e_aq_set_link_restart_an
  1184. * @hw: pointer to the hw struct
  1185. * @enable_link: if true: enable link, if false: disable link
  1186. * @cmd_details: pointer to command details structure or NULL
  1187. *
  1188. * Sets up the link and restarts the Auto-Negotiation over the link.
  1189. **/
  1190. i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
  1191. bool enable_link,
  1192. struct i40e_asq_cmd_details *cmd_details)
  1193. {
  1194. struct i40e_aq_desc desc;
  1195. struct i40e_aqc_set_link_restart_an *cmd =
  1196. (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
  1197. i40e_status status;
  1198. i40e_fill_default_direct_cmd_desc(&desc,
  1199. i40e_aqc_opc_set_link_restart_an);
  1200. cmd->command = I40E_AQ_PHY_RESTART_AN;
  1201. if (enable_link)
  1202. cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
  1203. else
  1204. cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
  1205. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1206. return status;
  1207. }
  1208. /**
  1209. * i40e_aq_get_link_info
  1210. * @hw: pointer to the hw struct
  1211. * @enable_lse: enable/disable LinkStatusEvent reporting
  1212. * @link: pointer to link status structure - optional
  1213. * @cmd_details: pointer to command details structure or NULL
  1214. *
  1215. * Returns the link status of the adapter.
  1216. **/
  1217. i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
  1218. bool enable_lse, struct i40e_link_status *link,
  1219. struct i40e_asq_cmd_details *cmd_details)
  1220. {
  1221. struct i40e_aq_desc desc;
  1222. struct i40e_aqc_get_link_status *resp =
  1223. (struct i40e_aqc_get_link_status *)&desc.params.raw;
  1224. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  1225. i40e_status status;
  1226. bool tx_pause, rx_pause;
  1227. u16 command_flags;
  1228. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
  1229. if (enable_lse)
  1230. command_flags = I40E_AQ_LSE_ENABLE;
  1231. else
  1232. command_flags = I40E_AQ_LSE_DISABLE;
  1233. resp->command_flags = cpu_to_le16(command_flags);
  1234. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1235. if (status)
  1236. goto aq_get_link_info_exit;
  1237. /* save off old link status information */
  1238. hw->phy.link_info_old = *hw_link_info;
  1239. /* update link status */
  1240. hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
  1241. hw->phy.media_type = i40e_get_media_type(hw);
  1242. hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
  1243. hw_link_info->link_info = resp->link_info;
  1244. hw_link_info->an_info = resp->an_info;
  1245. hw_link_info->ext_info = resp->ext_info;
  1246. hw_link_info->loopback = resp->loopback;
  1247. hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
  1248. hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
  1249. /* update fc info */
  1250. tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
  1251. rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
  1252. if (tx_pause & rx_pause)
  1253. hw->fc.current_mode = I40E_FC_FULL;
  1254. else if (tx_pause)
  1255. hw->fc.current_mode = I40E_FC_TX_PAUSE;
  1256. else if (rx_pause)
  1257. hw->fc.current_mode = I40E_FC_RX_PAUSE;
  1258. else
  1259. hw->fc.current_mode = I40E_FC_NONE;
  1260. if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
  1261. hw_link_info->crc_enable = true;
  1262. else
  1263. hw_link_info->crc_enable = false;
  1264. if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE))
  1265. hw_link_info->lse_enable = true;
  1266. else
  1267. hw_link_info->lse_enable = false;
  1268. /* save link status information */
  1269. if (link)
  1270. *link = *hw_link_info;
  1271. /* flag cleared so helper functions don't call AQ again */
  1272. hw->phy.get_link_info = false;
  1273. aq_get_link_info_exit:
  1274. return status;
  1275. }
  1276. /**
  1277. * i40e_aq_set_phy_int_mask
  1278. * @hw: pointer to the hw struct
  1279. * @mask: interrupt mask to be set
  1280. * @cmd_details: pointer to command details structure or NULL
  1281. *
  1282. * Set link interrupt mask.
  1283. **/
  1284. i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
  1285. u16 mask,
  1286. struct i40e_asq_cmd_details *cmd_details)
  1287. {
  1288. struct i40e_aq_desc desc;
  1289. struct i40e_aqc_set_phy_int_mask *cmd =
  1290. (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
  1291. i40e_status status;
  1292. i40e_fill_default_direct_cmd_desc(&desc,
  1293. i40e_aqc_opc_set_phy_int_mask);
  1294. cmd->event_mask = cpu_to_le16(mask);
  1295. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1296. return status;
  1297. }
  1298. /**
  1299. * i40e_aq_add_vsi
  1300. * @hw: pointer to the hw struct
  1301. * @vsi_ctx: pointer to a vsi context struct
  1302. * @cmd_details: pointer to command details structure or NULL
  1303. *
  1304. * Add a VSI context to the hardware.
  1305. **/
  1306. i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
  1307. struct i40e_vsi_context *vsi_ctx,
  1308. struct i40e_asq_cmd_details *cmd_details)
  1309. {
  1310. struct i40e_aq_desc desc;
  1311. struct i40e_aqc_add_get_update_vsi *cmd =
  1312. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1313. struct i40e_aqc_add_get_update_vsi_completion *resp =
  1314. (struct i40e_aqc_add_get_update_vsi_completion *)
  1315. &desc.params.raw;
  1316. i40e_status status;
  1317. i40e_fill_default_direct_cmd_desc(&desc,
  1318. i40e_aqc_opc_add_vsi);
  1319. cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
  1320. cmd->connection_type = vsi_ctx->connection_type;
  1321. cmd->vf_id = vsi_ctx->vf_num;
  1322. cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
  1323. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1324. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1325. sizeof(vsi_ctx->info), cmd_details);
  1326. if (status)
  1327. goto aq_add_vsi_exit;
  1328. vsi_ctx->seid = le16_to_cpu(resp->seid);
  1329. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  1330. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  1331. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  1332. aq_add_vsi_exit:
  1333. return status;
  1334. }
  1335. /**
  1336. * i40e_aq_set_vsi_unicast_promiscuous
  1337. * @hw: pointer to the hw struct
  1338. * @seid: vsi number
  1339. * @set: set unicast promiscuous enable/disable
  1340. * @cmd_details: pointer to command details structure or NULL
  1341. **/
  1342. i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
  1343. u16 seid, bool set,
  1344. struct i40e_asq_cmd_details *cmd_details)
  1345. {
  1346. struct i40e_aq_desc desc;
  1347. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1348. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1349. i40e_status status;
  1350. u16 flags = 0;
  1351. i40e_fill_default_direct_cmd_desc(&desc,
  1352. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1353. if (set)
  1354. flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
  1355. cmd->promiscuous_flags = cpu_to_le16(flags);
  1356. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
  1357. cmd->seid = cpu_to_le16(seid);
  1358. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1359. return status;
  1360. }
  1361. /**
  1362. * i40e_aq_set_vsi_multicast_promiscuous
  1363. * @hw: pointer to the hw struct
  1364. * @seid: vsi number
  1365. * @set: set multicast promiscuous enable/disable
  1366. * @cmd_details: pointer to command details structure or NULL
  1367. **/
  1368. i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
  1369. u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
  1370. {
  1371. struct i40e_aq_desc desc;
  1372. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1373. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1374. i40e_status status;
  1375. u16 flags = 0;
  1376. i40e_fill_default_direct_cmd_desc(&desc,
  1377. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1378. if (set)
  1379. flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
  1380. cmd->promiscuous_flags = cpu_to_le16(flags);
  1381. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
  1382. cmd->seid = cpu_to_le16(seid);
  1383. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1384. return status;
  1385. }
  1386. /**
  1387. * i40e_aq_set_vsi_broadcast
  1388. * @hw: pointer to the hw struct
  1389. * @seid: vsi number
  1390. * @set_filter: true to set filter, false to clear filter
  1391. * @cmd_details: pointer to command details structure or NULL
  1392. *
  1393. * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
  1394. **/
  1395. i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
  1396. u16 seid, bool set_filter,
  1397. struct i40e_asq_cmd_details *cmd_details)
  1398. {
  1399. struct i40e_aq_desc desc;
  1400. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1401. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1402. i40e_status status;
  1403. i40e_fill_default_direct_cmd_desc(&desc,
  1404. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1405. if (set_filter)
  1406. cmd->promiscuous_flags
  1407. |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1408. else
  1409. cmd->promiscuous_flags
  1410. &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1411. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1412. cmd->seid = cpu_to_le16(seid);
  1413. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1414. return status;
  1415. }
  1416. /**
  1417. * i40e_get_vsi_params - get VSI configuration info
  1418. * @hw: pointer to the hw struct
  1419. * @vsi_ctx: pointer to a vsi context struct
  1420. * @cmd_details: pointer to command details structure or NULL
  1421. **/
  1422. i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
  1423. struct i40e_vsi_context *vsi_ctx,
  1424. struct i40e_asq_cmd_details *cmd_details)
  1425. {
  1426. struct i40e_aq_desc desc;
  1427. struct i40e_aqc_add_get_update_vsi *cmd =
  1428. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1429. struct i40e_aqc_add_get_update_vsi_completion *resp =
  1430. (struct i40e_aqc_add_get_update_vsi_completion *)
  1431. &desc.params.raw;
  1432. i40e_status status;
  1433. i40e_fill_default_direct_cmd_desc(&desc,
  1434. i40e_aqc_opc_get_vsi_parameters);
  1435. cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
  1436. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1437. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1438. sizeof(vsi_ctx->info), NULL);
  1439. if (status)
  1440. goto aq_get_vsi_params_exit;
  1441. vsi_ctx->seid = le16_to_cpu(resp->seid);
  1442. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  1443. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  1444. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  1445. aq_get_vsi_params_exit:
  1446. return status;
  1447. }
  1448. /**
  1449. * i40e_aq_update_vsi_params
  1450. * @hw: pointer to the hw struct
  1451. * @vsi_ctx: pointer to a vsi context struct
  1452. * @cmd_details: pointer to command details structure or NULL
  1453. *
  1454. * Update a VSI context.
  1455. **/
  1456. i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
  1457. struct i40e_vsi_context *vsi_ctx,
  1458. struct i40e_asq_cmd_details *cmd_details)
  1459. {
  1460. struct i40e_aq_desc desc;
  1461. struct i40e_aqc_add_get_update_vsi *cmd =
  1462. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1463. i40e_status status;
  1464. i40e_fill_default_direct_cmd_desc(&desc,
  1465. i40e_aqc_opc_update_vsi_parameters);
  1466. cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
  1467. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1468. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1469. sizeof(vsi_ctx->info), cmd_details);
  1470. return status;
  1471. }
  1472. /**
  1473. * i40e_aq_get_switch_config
  1474. * @hw: pointer to the hardware structure
  1475. * @buf: pointer to the result buffer
  1476. * @buf_size: length of input buffer
  1477. * @start_seid: seid to start for the report, 0 == beginning
  1478. * @cmd_details: pointer to command details structure or NULL
  1479. *
  1480. * Fill the buf with switch configuration returned from AdminQ command
  1481. **/
  1482. i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
  1483. struct i40e_aqc_get_switch_config_resp *buf,
  1484. u16 buf_size, u16 *start_seid,
  1485. struct i40e_asq_cmd_details *cmd_details)
  1486. {
  1487. struct i40e_aq_desc desc;
  1488. struct i40e_aqc_switch_seid *scfg =
  1489. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  1490. i40e_status status;
  1491. i40e_fill_default_direct_cmd_desc(&desc,
  1492. i40e_aqc_opc_get_switch_config);
  1493. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1494. if (buf_size > I40E_AQ_LARGE_BUF)
  1495. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1496. scfg->seid = cpu_to_le16(*start_seid);
  1497. status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
  1498. *start_seid = le16_to_cpu(scfg->seid);
  1499. return status;
  1500. }
  1501. /**
  1502. * i40e_aq_get_firmware_version
  1503. * @hw: pointer to the hw struct
  1504. * @fw_major_version: firmware major version
  1505. * @fw_minor_version: firmware minor version
  1506. * @api_major_version: major queue version
  1507. * @api_minor_version: minor queue version
  1508. * @cmd_details: pointer to command details structure or NULL
  1509. *
  1510. * Get the firmware version from the admin queue commands
  1511. **/
  1512. i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
  1513. u16 *fw_major_version, u16 *fw_minor_version,
  1514. u16 *api_major_version, u16 *api_minor_version,
  1515. struct i40e_asq_cmd_details *cmd_details)
  1516. {
  1517. struct i40e_aq_desc desc;
  1518. struct i40e_aqc_get_version *resp =
  1519. (struct i40e_aqc_get_version *)&desc.params.raw;
  1520. i40e_status status;
  1521. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
  1522. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1523. if (!status) {
  1524. if (fw_major_version != NULL)
  1525. *fw_major_version = le16_to_cpu(resp->fw_major);
  1526. if (fw_minor_version != NULL)
  1527. *fw_minor_version = le16_to_cpu(resp->fw_minor);
  1528. if (api_major_version != NULL)
  1529. *api_major_version = le16_to_cpu(resp->api_major);
  1530. if (api_minor_version != NULL)
  1531. *api_minor_version = le16_to_cpu(resp->api_minor);
  1532. }
  1533. return status;
  1534. }
  1535. /**
  1536. * i40e_aq_send_driver_version
  1537. * @hw: pointer to the hw struct
  1538. * @dv: driver's major, minor version
  1539. * @cmd_details: pointer to command details structure or NULL
  1540. *
  1541. * Send the driver version to the firmware
  1542. **/
  1543. i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
  1544. struct i40e_driver_version *dv,
  1545. struct i40e_asq_cmd_details *cmd_details)
  1546. {
  1547. struct i40e_aq_desc desc;
  1548. struct i40e_aqc_driver_version *cmd =
  1549. (struct i40e_aqc_driver_version *)&desc.params.raw;
  1550. i40e_status status;
  1551. u16 len;
  1552. if (dv == NULL)
  1553. return I40E_ERR_PARAM;
  1554. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
  1555. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
  1556. cmd->driver_major_ver = dv->major_version;
  1557. cmd->driver_minor_ver = dv->minor_version;
  1558. cmd->driver_build_ver = dv->build_version;
  1559. cmd->driver_subbuild_ver = dv->subbuild_version;
  1560. len = 0;
  1561. while (len < sizeof(dv->driver_string) &&
  1562. (dv->driver_string[len] < 0x80) &&
  1563. dv->driver_string[len])
  1564. len++;
  1565. status = i40e_asq_send_command(hw, &desc, dv->driver_string,
  1566. len, cmd_details);
  1567. return status;
  1568. }
  1569. /**
  1570. * i40e_get_link_status - get status of the HW network link
  1571. * @hw: pointer to the hw struct
  1572. *
  1573. * Returns true if link is up, false if link is down.
  1574. *
  1575. * Side effect: LinkStatusEvent reporting becomes enabled
  1576. **/
  1577. bool i40e_get_link_status(struct i40e_hw *hw)
  1578. {
  1579. i40e_status status = 0;
  1580. bool link_status = false;
  1581. if (hw->phy.get_link_info) {
  1582. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  1583. if (status)
  1584. goto i40e_get_link_status_exit;
  1585. }
  1586. link_status = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  1587. i40e_get_link_status_exit:
  1588. return link_status;
  1589. }
  1590. /**
  1591. * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
  1592. * @hw: pointer to the hw struct
  1593. * @uplink_seid: the MAC or other gizmo SEID
  1594. * @downlink_seid: the VSI SEID
  1595. * @enabled_tc: bitmap of TCs to be enabled
  1596. * @default_port: true for default port VSI, false for control port
  1597. * @enable_l2_filtering: true to add L2 filter table rules to regular forwarding rules for cloud support
  1598. * @veb_seid: pointer to where to put the resulting VEB SEID
  1599. * @cmd_details: pointer to command details structure or NULL
  1600. *
  1601. * This asks the FW to add a VEB between the uplink and downlink
  1602. * elements. If the uplink SEID is 0, this will be a floating VEB.
  1603. **/
  1604. i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
  1605. u16 downlink_seid, u8 enabled_tc,
  1606. bool default_port, bool enable_l2_filtering,
  1607. u16 *veb_seid,
  1608. struct i40e_asq_cmd_details *cmd_details)
  1609. {
  1610. struct i40e_aq_desc desc;
  1611. struct i40e_aqc_add_veb *cmd =
  1612. (struct i40e_aqc_add_veb *)&desc.params.raw;
  1613. struct i40e_aqc_add_veb_completion *resp =
  1614. (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
  1615. i40e_status status;
  1616. u16 veb_flags = 0;
  1617. /* SEIDs need to either both be set or both be 0 for floating VEB */
  1618. if (!!uplink_seid != !!downlink_seid)
  1619. return I40E_ERR_PARAM;
  1620. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
  1621. cmd->uplink_seid = cpu_to_le16(uplink_seid);
  1622. cmd->downlink_seid = cpu_to_le16(downlink_seid);
  1623. cmd->enable_tcs = enabled_tc;
  1624. if (!uplink_seid)
  1625. veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
  1626. if (default_port)
  1627. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
  1628. else
  1629. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
  1630. if (enable_l2_filtering)
  1631. veb_flags |= I40E_AQC_ADD_VEB_ENABLE_L2_FILTER;
  1632. cmd->veb_flags = cpu_to_le16(veb_flags);
  1633. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1634. if (!status && veb_seid)
  1635. *veb_seid = le16_to_cpu(resp->veb_seid);
  1636. return status;
  1637. }
  1638. /**
  1639. * i40e_aq_get_veb_parameters - Retrieve VEB parameters
  1640. * @hw: pointer to the hw struct
  1641. * @veb_seid: the SEID of the VEB to query
  1642. * @switch_id: the uplink switch id
  1643. * @floating: set to true if the VEB is floating
  1644. * @statistic_index: index of the stats counter block for this VEB
  1645. * @vebs_used: number of VEB's used by function
  1646. * @vebs_free: total VEB's not reserved by any function
  1647. * @cmd_details: pointer to command details structure or NULL
  1648. *
  1649. * This retrieves the parameters for a particular VEB, specified by
  1650. * uplink_seid, and returns them to the caller.
  1651. **/
  1652. i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
  1653. u16 veb_seid, u16 *switch_id,
  1654. bool *floating, u16 *statistic_index,
  1655. u16 *vebs_used, u16 *vebs_free,
  1656. struct i40e_asq_cmd_details *cmd_details)
  1657. {
  1658. struct i40e_aq_desc desc;
  1659. struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
  1660. (struct i40e_aqc_get_veb_parameters_completion *)
  1661. &desc.params.raw;
  1662. i40e_status status;
  1663. if (veb_seid == 0)
  1664. return I40E_ERR_PARAM;
  1665. i40e_fill_default_direct_cmd_desc(&desc,
  1666. i40e_aqc_opc_get_veb_parameters);
  1667. cmd_resp->seid = cpu_to_le16(veb_seid);
  1668. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1669. if (status)
  1670. goto get_veb_exit;
  1671. if (switch_id)
  1672. *switch_id = le16_to_cpu(cmd_resp->switch_id);
  1673. if (statistic_index)
  1674. *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
  1675. if (vebs_used)
  1676. *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
  1677. if (vebs_free)
  1678. *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
  1679. if (floating) {
  1680. u16 flags = le16_to_cpu(cmd_resp->veb_flags);
  1681. if (flags & I40E_AQC_ADD_VEB_FLOATING)
  1682. *floating = true;
  1683. else
  1684. *floating = false;
  1685. }
  1686. get_veb_exit:
  1687. return status;
  1688. }
  1689. /**
  1690. * i40e_aq_add_macvlan
  1691. * @hw: pointer to the hw struct
  1692. * @seid: VSI for the mac address
  1693. * @mv_list: list of macvlans to be added
  1694. * @count: length of the list
  1695. * @cmd_details: pointer to command details structure or NULL
  1696. *
  1697. * Add MAC/VLAN addresses to the HW filtering
  1698. **/
  1699. i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
  1700. struct i40e_aqc_add_macvlan_element_data *mv_list,
  1701. u16 count, struct i40e_asq_cmd_details *cmd_details)
  1702. {
  1703. struct i40e_aq_desc desc;
  1704. struct i40e_aqc_macvlan *cmd =
  1705. (struct i40e_aqc_macvlan *)&desc.params.raw;
  1706. i40e_status status;
  1707. u16 buf_size;
  1708. if (count == 0 || !mv_list || !hw)
  1709. return I40E_ERR_PARAM;
  1710. buf_size = count * sizeof(struct i40e_aqc_add_macvlan_element_data);
  1711. /* prep the rest of the request */
  1712. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
  1713. cmd->num_addresses = cpu_to_le16(count);
  1714. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  1715. cmd->seid[1] = 0;
  1716. cmd->seid[2] = 0;
  1717. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1718. if (buf_size > I40E_AQ_LARGE_BUF)
  1719. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1720. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  1721. cmd_details);
  1722. return status;
  1723. }
  1724. /**
  1725. * i40e_aq_remove_macvlan
  1726. * @hw: pointer to the hw struct
  1727. * @seid: VSI for the mac address
  1728. * @mv_list: list of macvlans to be removed
  1729. * @count: length of the list
  1730. * @cmd_details: pointer to command details structure or NULL
  1731. *
  1732. * Remove MAC/VLAN addresses from the HW filtering
  1733. **/
  1734. i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
  1735. struct i40e_aqc_remove_macvlan_element_data *mv_list,
  1736. u16 count, struct i40e_asq_cmd_details *cmd_details)
  1737. {
  1738. struct i40e_aq_desc desc;
  1739. struct i40e_aqc_macvlan *cmd =
  1740. (struct i40e_aqc_macvlan *)&desc.params.raw;
  1741. i40e_status status;
  1742. u16 buf_size;
  1743. if (count == 0 || !mv_list || !hw)
  1744. return I40E_ERR_PARAM;
  1745. buf_size = count * sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1746. /* prep the rest of the request */
  1747. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
  1748. cmd->num_addresses = cpu_to_le16(count);
  1749. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  1750. cmd->seid[1] = 0;
  1751. cmd->seid[2] = 0;
  1752. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1753. if (buf_size > I40E_AQ_LARGE_BUF)
  1754. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1755. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  1756. cmd_details);
  1757. return status;
  1758. }
  1759. /**
  1760. * i40e_aq_send_msg_to_vf
  1761. * @hw: pointer to the hardware structure
  1762. * @vfid: vf id to send msg
  1763. * @v_opcode: opcodes for VF-PF communication
  1764. * @v_retval: return error code
  1765. * @msg: pointer to the msg buffer
  1766. * @msglen: msg length
  1767. * @cmd_details: pointer to command details
  1768. *
  1769. * send msg to vf
  1770. **/
  1771. i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
  1772. u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
  1773. struct i40e_asq_cmd_details *cmd_details)
  1774. {
  1775. struct i40e_aq_desc desc;
  1776. struct i40e_aqc_pf_vf_message *cmd =
  1777. (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
  1778. i40e_status status;
  1779. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
  1780. cmd->id = cpu_to_le32(vfid);
  1781. desc.cookie_high = cpu_to_le32(v_opcode);
  1782. desc.cookie_low = cpu_to_le32(v_retval);
  1783. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
  1784. if (msglen) {
  1785. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
  1786. I40E_AQ_FLAG_RD));
  1787. if (msglen > I40E_AQ_LARGE_BUF)
  1788. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1789. desc.datalen = cpu_to_le16(msglen);
  1790. }
  1791. status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
  1792. return status;
  1793. }
  1794. /**
  1795. * i40e_aq_debug_read_register
  1796. * @hw: pointer to the hw struct
  1797. * @reg_addr: register address
  1798. * @reg_val: register value
  1799. * @cmd_details: pointer to command details structure or NULL
  1800. *
  1801. * Read the register using the admin queue commands
  1802. **/
  1803. i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
  1804. u32 reg_addr, u64 *reg_val,
  1805. struct i40e_asq_cmd_details *cmd_details)
  1806. {
  1807. struct i40e_aq_desc desc;
  1808. struct i40e_aqc_debug_reg_read_write *cmd_resp =
  1809. (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
  1810. i40e_status status;
  1811. if (reg_val == NULL)
  1812. return I40E_ERR_PARAM;
  1813. i40e_fill_default_direct_cmd_desc(&desc,
  1814. i40e_aqc_opc_debug_read_reg);
  1815. cmd_resp->address = cpu_to_le32(reg_addr);
  1816. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1817. if (!status) {
  1818. *reg_val = ((u64)cmd_resp->value_high << 32) |
  1819. (u64)cmd_resp->value_low;
  1820. *reg_val = le64_to_cpu(*reg_val);
  1821. }
  1822. return status;
  1823. }
  1824. /**
  1825. * i40e_aq_debug_write_register
  1826. * @hw: pointer to the hw struct
  1827. * @reg_addr: register address
  1828. * @reg_val: register value
  1829. * @cmd_details: pointer to command details structure or NULL
  1830. *
  1831. * Write to a register using the admin queue commands
  1832. **/
  1833. i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
  1834. u32 reg_addr, u64 reg_val,
  1835. struct i40e_asq_cmd_details *cmd_details)
  1836. {
  1837. struct i40e_aq_desc desc;
  1838. struct i40e_aqc_debug_reg_read_write *cmd =
  1839. (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
  1840. i40e_status status;
  1841. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
  1842. cmd->address = cpu_to_le32(reg_addr);
  1843. cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
  1844. cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
  1845. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1846. return status;
  1847. }
  1848. /**
  1849. * i40e_aq_set_hmc_resource_profile
  1850. * @hw: pointer to the hw struct
  1851. * @profile: type of profile the HMC is to be set as
  1852. * @pe_vf_enabled_count: the number of PE enabled VFs the system has
  1853. * @cmd_details: pointer to command details structure or NULL
  1854. *
  1855. * set the HMC profile of the device.
  1856. **/
  1857. i40e_status i40e_aq_set_hmc_resource_profile(struct i40e_hw *hw,
  1858. enum i40e_aq_hmc_profile profile,
  1859. u8 pe_vf_enabled_count,
  1860. struct i40e_asq_cmd_details *cmd_details)
  1861. {
  1862. struct i40e_aq_desc desc;
  1863. struct i40e_aq_get_set_hmc_resource_profile *cmd =
  1864. (struct i40e_aq_get_set_hmc_resource_profile *)&desc.params.raw;
  1865. i40e_status status;
  1866. i40e_fill_default_direct_cmd_desc(&desc,
  1867. i40e_aqc_opc_set_hmc_resource_profile);
  1868. cmd->pm_profile = (u8)profile;
  1869. cmd->pe_vf_enabled = pe_vf_enabled_count;
  1870. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1871. return status;
  1872. }
  1873. /**
  1874. * i40e_aq_request_resource
  1875. * @hw: pointer to the hw struct
  1876. * @resource: resource id
  1877. * @access: access type
  1878. * @sdp_number: resource number
  1879. * @timeout: the maximum time in ms that the driver may hold the resource
  1880. * @cmd_details: pointer to command details structure or NULL
  1881. *
  1882. * requests common resource using the admin queue commands
  1883. **/
  1884. i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
  1885. enum i40e_aq_resources_ids resource,
  1886. enum i40e_aq_resource_access_type access,
  1887. u8 sdp_number, u64 *timeout,
  1888. struct i40e_asq_cmd_details *cmd_details)
  1889. {
  1890. struct i40e_aq_desc desc;
  1891. struct i40e_aqc_request_resource *cmd_resp =
  1892. (struct i40e_aqc_request_resource *)&desc.params.raw;
  1893. i40e_status status;
  1894. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
  1895. cmd_resp->resource_id = cpu_to_le16(resource);
  1896. cmd_resp->access_type = cpu_to_le16(access);
  1897. cmd_resp->resource_number = cpu_to_le32(sdp_number);
  1898. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1899. /* The completion specifies the maximum time in ms that the driver
  1900. * may hold the resource in the Timeout field.
  1901. * If the resource is held by someone else, the command completes with
  1902. * busy return value and the timeout field indicates the maximum time
  1903. * the current owner of the resource has to free it.
  1904. */
  1905. if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
  1906. *timeout = le32_to_cpu(cmd_resp->timeout);
  1907. return status;
  1908. }
  1909. /**
  1910. * i40e_aq_release_resource
  1911. * @hw: pointer to the hw struct
  1912. * @resource: resource id
  1913. * @sdp_number: resource number
  1914. * @cmd_details: pointer to command details structure or NULL
  1915. *
  1916. * release common resource using the admin queue commands
  1917. **/
  1918. i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
  1919. enum i40e_aq_resources_ids resource,
  1920. u8 sdp_number,
  1921. struct i40e_asq_cmd_details *cmd_details)
  1922. {
  1923. struct i40e_aq_desc desc;
  1924. struct i40e_aqc_request_resource *cmd =
  1925. (struct i40e_aqc_request_resource *)&desc.params.raw;
  1926. i40e_status status;
  1927. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
  1928. cmd->resource_id = cpu_to_le16(resource);
  1929. cmd->resource_number = cpu_to_le32(sdp_number);
  1930. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1931. return status;
  1932. }
  1933. /**
  1934. * i40e_aq_read_nvm
  1935. * @hw: pointer to the hw struct
  1936. * @module_pointer: module pointer location in words from the NVM beginning
  1937. * @offset: byte offset from the module beginning
  1938. * @length: length of the section to be read (in bytes from the offset)
  1939. * @data: command buffer (size [bytes] = length)
  1940. * @last_command: tells if this is the last command in a series
  1941. * @cmd_details: pointer to command details structure or NULL
  1942. *
  1943. * Read the NVM using the admin queue commands
  1944. **/
  1945. i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
  1946. u32 offset, u16 length, void *data,
  1947. bool last_command,
  1948. struct i40e_asq_cmd_details *cmd_details)
  1949. {
  1950. struct i40e_aq_desc desc;
  1951. struct i40e_aqc_nvm_update *cmd =
  1952. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  1953. i40e_status status;
  1954. /* In offset the highest byte must be zeroed. */
  1955. if (offset & 0xFF000000) {
  1956. status = I40E_ERR_PARAM;
  1957. goto i40e_aq_read_nvm_exit;
  1958. }
  1959. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
  1960. /* If this is the last command in a series, set the proper flag. */
  1961. if (last_command)
  1962. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  1963. cmd->module_pointer = module_pointer;
  1964. cmd->offset = cpu_to_le32(offset);
  1965. cmd->length = cpu_to_le16(length);
  1966. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1967. if (length > I40E_AQ_LARGE_BUF)
  1968. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1969. status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
  1970. i40e_aq_read_nvm_exit:
  1971. return status;
  1972. }
  1973. /**
  1974. * i40e_aq_erase_nvm
  1975. * @hw: pointer to the hw struct
  1976. * @module_pointer: module pointer location in words from the NVM beginning
  1977. * @offset: offset in the module (expressed in 4 KB from module's beginning)
  1978. * @length: length of the section to be erased (expressed in 4 KB)
  1979. * @last_command: tells if this is the last command in a series
  1980. * @cmd_details: pointer to command details structure or NULL
  1981. *
  1982. * Erase the NVM sector using the admin queue commands
  1983. **/
  1984. i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
  1985. u32 offset, u16 length, bool last_command,
  1986. struct i40e_asq_cmd_details *cmd_details)
  1987. {
  1988. struct i40e_aq_desc desc;
  1989. struct i40e_aqc_nvm_update *cmd =
  1990. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  1991. i40e_status status;
  1992. /* In offset the highest byte must be zeroed. */
  1993. if (offset & 0xFF000000) {
  1994. status = I40E_ERR_PARAM;
  1995. goto i40e_aq_erase_nvm_exit;
  1996. }
  1997. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
  1998. /* If this is the last command in a series, set the proper flag. */
  1999. if (last_command)
  2000. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2001. cmd->module_pointer = module_pointer;
  2002. cmd->offset = cpu_to_le32(offset);
  2003. cmd->length = cpu_to_le16(length);
  2004. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2005. i40e_aq_erase_nvm_exit:
  2006. return status;
  2007. }
  2008. #define I40E_DEV_FUNC_CAP_SWITCH_MODE 0x01
  2009. #define I40E_DEV_FUNC_CAP_MGMT_MODE 0x02
  2010. #define I40E_DEV_FUNC_CAP_NPAR 0x03
  2011. #define I40E_DEV_FUNC_CAP_OS2BMC 0x04
  2012. #define I40E_DEV_FUNC_CAP_VALID_FUNC 0x05
  2013. #define I40E_DEV_FUNC_CAP_SRIOV_1_1 0x12
  2014. #define I40E_DEV_FUNC_CAP_VF 0x13
  2015. #define I40E_DEV_FUNC_CAP_VMDQ 0x14
  2016. #define I40E_DEV_FUNC_CAP_802_1_QBG 0x15
  2017. #define I40E_DEV_FUNC_CAP_802_1_QBH 0x16
  2018. #define I40E_DEV_FUNC_CAP_VSI 0x17
  2019. #define I40E_DEV_FUNC_CAP_DCB 0x18
  2020. #define I40E_DEV_FUNC_CAP_FCOE 0x21
  2021. #define I40E_DEV_FUNC_CAP_ISCSI 0x22
  2022. #define I40E_DEV_FUNC_CAP_RSS 0x40
  2023. #define I40E_DEV_FUNC_CAP_RX_QUEUES 0x41
  2024. #define I40E_DEV_FUNC_CAP_TX_QUEUES 0x42
  2025. #define I40E_DEV_FUNC_CAP_MSIX 0x43
  2026. #define I40E_DEV_FUNC_CAP_MSIX_VF 0x44
  2027. #define I40E_DEV_FUNC_CAP_FLOW_DIRECTOR 0x45
  2028. #define I40E_DEV_FUNC_CAP_IEEE_1588 0x46
  2029. #define I40E_DEV_FUNC_CAP_MFP_MODE_1 0xF1
  2030. #define I40E_DEV_FUNC_CAP_CEM 0xF2
  2031. #define I40E_DEV_FUNC_CAP_IWARP 0x51
  2032. #define I40E_DEV_FUNC_CAP_LED 0x61
  2033. #define I40E_DEV_FUNC_CAP_SDP 0x62
  2034. #define I40E_DEV_FUNC_CAP_MDIO 0x63
  2035. /**
  2036. * i40e_parse_discover_capabilities
  2037. * @hw: pointer to the hw struct
  2038. * @buff: pointer to a buffer containing device/function capability records
  2039. * @cap_count: number of capability records in the list
  2040. * @list_type_opc: type of capabilities list to parse
  2041. *
  2042. * Parse the device/function capabilities list.
  2043. **/
  2044. static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
  2045. u32 cap_count,
  2046. enum i40e_admin_queue_opc list_type_opc)
  2047. {
  2048. struct i40e_aqc_list_capabilities_element_resp *cap;
  2049. u32 valid_functions, num_functions;
  2050. u32 number, logical_id, phys_id;
  2051. struct i40e_hw_capabilities *p;
  2052. u32 i = 0;
  2053. u16 id;
  2054. cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
  2055. if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
  2056. p = &hw->dev_caps;
  2057. else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
  2058. p = &hw->func_caps;
  2059. else
  2060. return;
  2061. for (i = 0; i < cap_count; i++, cap++) {
  2062. id = le16_to_cpu(cap->id);
  2063. number = le32_to_cpu(cap->number);
  2064. logical_id = le32_to_cpu(cap->logical_id);
  2065. phys_id = le32_to_cpu(cap->phys_id);
  2066. switch (id) {
  2067. case I40E_DEV_FUNC_CAP_SWITCH_MODE:
  2068. p->switch_mode = number;
  2069. break;
  2070. case I40E_DEV_FUNC_CAP_MGMT_MODE:
  2071. p->management_mode = number;
  2072. break;
  2073. case I40E_DEV_FUNC_CAP_NPAR:
  2074. p->npar_enable = number;
  2075. break;
  2076. case I40E_DEV_FUNC_CAP_OS2BMC:
  2077. p->os2bmc = number;
  2078. break;
  2079. case I40E_DEV_FUNC_CAP_VALID_FUNC:
  2080. p->valid_functions = number;
  2081. break;
  2082. case I40E_DEV_FUNC_CAP_SRIOV_1_1:
  2083. if (number == 1)
  2084. p->sr_iov_1_1 = true;
  2085. break;
  2086. case I40E_DEV_FUNC_CAP_VF:
  2087. p->num_vfs = number;
  2088. p->vf_base_id = logical_id;
  2089. break;
  2090. case I40E_DEV_FUNC_CAP_VMDQ:
  2091. if (number == 1)
  2092. p->vmdq = true;
  2093. break;
  2094. case I40E_DEV_FUNC_CAP_802_1_QBG:
  2095. if (number == 1)
  2096. p->evb_802_1_qbg = true;
  2097. break;
  2098. case I40E_DEV_FUNC_CAP_802_1_QBH:
  2099. if (number == 1)
  2100. p->evb_802_1_qbh = true;
  2101. break;
  2102. case I40E_DEV_FUNC_CAP_VSI:
  2103. p->num_vsis = number;
  2104. break;
  2105. case I40E_DEV_FUNC_CAP_DCB:
  2106. if (number == 1) {
  2107. p->dcb = true;
  2108. p->enabled_tcmap = logical_id;
  2109. p->maxtc = phys_id;
  2110. }
  2111. break;
  2112. case I40E_DEV_FUNC_CAP_FCOE:
  2113. if (number == 1)
  2114. p->fcoe = true;
  2115. break;
  2116. case I40E_DEV_FUNC_CAP_ISCSI:
  2117. if (number == 1)
  2118. p->iscsi = true;
  2119. break;
  2120. case I40E_DEV_FUNC_CAP_RSS:
  2121. p->rss = true;
  2122. p->rss_table_size = number;
  2123. p->rss_table_entry_width = logical_id;
  2124. break;
  2125. case I40E_DEV_FUNC_CAP_RX_QUEUES:
  2126. p->num_rx_qp = number;
  2127. p->base_queue = phys_id;
  2128. break;
  2129. case I40E_DEV_FUNC_CAP_TX_QUEUES:
  2130. p->num_tx_qp = number;
  2131. p->base_queue = phys_id;
  2132. break;
  2133. case I40E_DEV_FUNC_CAP_MSIX:
  2134. p->num_msix_vectors = number;
  2135. break;
  2136. case I40E_DEV_FUNC_CAP_MSIX_VF:
  2137. p->num_msix_vectors_vf = number;
  2138. break;
  2139. case I40E_DEV_FUNC_CAP_MFP_MODE_1:
  2140. if (number == 1)
  2141. p->mfp_mode_1 = true;
  2142. break;
  2143. case I40E_DEV_FUNC_CAP_CEM:
  2144. if (number == 1)
  2145. p->mgmt_cem = true;
  2146. break;
  2147. case I40E_DEV_FUNC_CAP_IWARP:
  2148. if (number == 1)
  2149. p->iwarp = true;
  2150. break;
  2151. case I40E_DEV_FUNC_CAP_LED:
  2152. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  2153. p->led[phys_id] = true;
  2154. break;
  2155. case I40E_DEV_FUNC_CAP_SDP:
  2156. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  2157. p->sdp[phys_id] = true;
  2158. break;
  2159. case I40E_DEV_FUNC_CAP_MDIO:
  2160. if (number == 1) {
  2161. p->mdio_port_num = phys_id;
  2162. p->mdio_port_mode = logical_id;
  2163. }
  2164. break;
  2165. case I40E_DEV_FUNC_CAP_IEEE_1588:
  2166. if (number == 1)
  2167. p->ieee_1588 = true;
  2168. break;
  2169. case I40E_DEV_FUNC_CAP_FLOW_DIRECTOR:
  2170. p->fd = true;
  2171. p->fd_filters_guaranteed = number;
  2172. p->fd_filters_best_effort = logical_id;
  2173. break;
  2174. default:
  2175. break;
  2176. }
  2177. }
  2178. /* Software override ensuring FCoE is disabled if npar or mfp
  2179. * mode because it is not supported in these modes.
  2180. */
  2181. if (p->npar_enable || p->mfp_mode_1)
  2182. p->fcoe = false;
  2183. /* count the enabled ports (aka the "not disabled" ports) */
  2184. hw->num_ports = 0;
  2185. for (i = 0; i < 4; i++) {
  2186. u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
  2187. u64 port_cfg = 0;
  2188. /* use AQ read to get the physical register offset instead
  2189. * of the port relative offset
  2190. */
  2191. i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
  2192. if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
  2193. hw->num_ports++;
  2194. }
  2195. valid_functions = p->valid_functions;
  2196. num_functions = 0;
  2197. while (valid_functions) {
  2198. if (valid_functions & 1)
  2199. num_functions++;
  2200. valid_functions >>= 1;
  2201. }
  2202. /* partition id is 1-based, and functions are evenly spread
  2203. * across the ports as partitions
  2204. */
  2205. hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
  2206. hw->num_partitions = num_functions / hw->num_ports;
  2207. /* additional HW specific goodies that might
  2208. * someday be HW version specific
  2209. */
  2210. p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
  2211. }
  2212. /**
  2213. * i40e_aq_discover_capabilities
  2214. * @hw: pointer to the hw struct
  2215. * @buff: a virtual buffer to hold the capabilities
  2216. * @buff_size: Size of the virtual buffer
  2217. * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
  2218. * @list_type_opc: capabilities type to discover - pass in the command opcode
  2219. * @cmd_details: pointer to command details structure or NULL
  2220. *
  2221. * Get the device capabilities descriptions from the firmware
  2222. **/
  2223. i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
  2224. void *buff, u16 buff_size, u16 *data_size,
  2225. enum i40e_admin_queue_opc list_type_opc,
  2226. struct i40e_asq_cmd_details *cmd_details)
  2227. {
  2228. struct i40e_aqc_list_capabilites *cmd;
  2229. struct i40e_aq_desc desc;
  2230. i40e_status status = 0;
  2231. cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
  2232. if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
  2233. list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
  2234. status = I40E_ERR_PARAM;
  2235. goto exit;
  2236. }
  2237. i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
  2238. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2239. if (buff_size > I40E_AQ_LARGE_BUF)
  2240. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2241. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2242. *data_size = le16_to_cpu(desc.datalen);
  2243. if (status)
  2244. goto exit;
  2245. i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
  2246. list_type_opc);
  2247. exit:
  2248. return status;
  2249. }
  2250. /**
  2251. * i40e_aq_update_nvm
  2252. * @hw: pointer to the hw struct
  2253. * @module_pointer: module pointer location in words from the NVM beginning
  2254. * @offset: byte offset from the module beginning
  2255. * @length: length of the section to be written (in bytes from the offset)
  2256. * @data: command buffer (size [bytes] = length)
  2257. * @last_command: tells if this is the last command in a series
  2258. * @cmd_details: pointer to command details structure or NULL
  2259. *
  2260. * Update the NVM using the admin queue commands
  2261. **/
  2262. i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
  2263. u32 offset, u16 length, void *data,
  2264. bool last_command,
  2265. struct i40e_asq_cmd_details *cmd_details)
  2266. {
  2267. struct i40e_aq_desc desc;
  2268. struct i40e_aqc_nvm_update *cmd =
  2269. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  2270. i40e_status status;
  2271. /* In offset the highest byte must be zeroed. */
  2272. if (offset & 0xFF000000) {
  2273. status = I40E_ERR_PARAM;
  2274. goto i40e_aq_update_nvm_exit;
  2275. }
  2276. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
  2277. /* If this is the last command in a series, set the proper flag. */
  2278. if (last_command)
  2279. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2280. cmd->module_pointer = module_pointer;
  2281. cmd->offset = cpu_to_le32(offset);
  2282. cmd->length = cpu_to_le16(length);
  2283. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  2284. if (length > I40E_AQ_LARGE_BUF)
  2285. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2286. status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
  2287. i40e_aq_update_nvm_exit:
  2288. return status;
  2289. }
  2290. /**
  2291. * i40e_aq_get_lldp_mib
  2292. * @hw: pointer to the hw struct
  2293. * @bridge_type: type of bridge requested
  2294. * @mib_type: Local, Remote or both Local and Remote MIBs
  2295. * @buff: pointer to a user supplied buffer to store the MIB block
  2296. * @buff_size: size of the buffer (in bytes)
  2297. * @local_len : length of the returned Local LLDP MIB
  2298. * @remote_len: length of the returned Remote LLDP MIB
  2299. * @cmd_details: pointer to command details structure or NULL
  2300. *
  2301. * Requests the complete LLDP MIB (entire packet).
  2302. **/
  2303. i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
  2304. u8 mib_type, void *buff, u16 buff_size,
  2305. u16 *local_len, u16 *remote_len,
  2306. struct i40e_asq_cmd_details *cmd_details)
  2307. {
  2308. struct i40e_aq_desc desc;
  2309. struct i40e_aqc_lldp_get_mib *cmd =
  2310. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  2311. struct i40e_aqc_lldp_get_mib *resp =
  2312. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  2313. i40e_status status;
  2314. if (buff_size == 0 || !buff)
  2315. return I40E_ERR_PARAM;
  2316. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
  2317. /* Indirect Command */
  2318. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2319. cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  2320. cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
  2321. I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  2322. desc.datalen = cpu_to_le16(buff_size);
  2323. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2324. if (buff_size > I40E_AQ_LARGE_BUF)
  2325. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2326. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2327. if (!status) {
  2328. if (local_len != NULL)
  2329. *local_len = le16_to_cpu(resp->local_len);
  2330. if (remote_len != NULL)
  2331. *remote_len = le16_to_cpu(resp->remote_len);
  2332. }
  2333. return status;
  2334. }
  2335. /**
  2336. * i40e_aq_cfg_lldp_mib_change_event
  2337. * @hw: pointer to the hw struct
  2338. * @enable_update: Enable or Disable event posting
  2339. * @cmd_details: pointer to command details structure or NULL
  2340. *
  2341. * Enable or Disable posting of an event on ARQ when LLDP MIB
  2342. * associated with the interface changes
  2343. **/
  2344. i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
  2345. bool enable_update,
  2346. struct i40e_asq_cmd_details *cmd_details)
  2347. {
  2348. struct i40e_aq_desc desc;
  2349. struct i40e_aqc_lldp_update_mib *cmd =
  2350. (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
  2351. i40e_status status;
  2352. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
  2353. if (!enable_update)
  2354. cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
  2355. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2356. return status;
  2357. }
  2358. /**
  2359. * i40e_aq_stop_lldp
  2360. * @hw: pointer to the hw struct
  2361. * @shutdown_agent: True if LLDP Agent needs to be Shutdown
  2362. * @cmd_details: pointer to command details structure or NULL
  2363. *
  2364. * Stop or Shutdown the embedded LLDP Agent
  2365. **/
  2366. i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
  2367. struct i40e_asq_cmd_details *cmd_details)
  2368. {
  2369. struct i40e_aq_desc desc;
  2370. struct i40e_aqc_lldp_stop *cmd =
  2371. (struct i40e_aqc_lldp_stop *)&desc.params.raw;
  2372. i40e_status status;
  2373. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
  2374. if (shutdown_agent)
  2375. cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
  2376. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2377. return status;
  2378. }
  2379. /**
  2380. * i40e_aq_start_lldp
  2381. * @hw: pointer to the hw struct
  2382. * @cmd_details: pointer to command details structure or NULL
  2383. *
  2384. * Start the embedded LLDP Agent on all ports.
  2385. **/
  2386. i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
  2387. struct i40e_asq_cmd_details *cmd_details)
  2388. {
  2389. struct i40e_aq_desc desc;
  2390. struct i40e_aqc_lldp_start *cmd =
  2391. (struct i40e_aqc_lldp_start *)&desc.params.raw;
  2392. i40e_status status;
  2393. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
  2394. cmd->command = I40E_AQ_LLDP_AGENT_START;
  2395. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2396. return status;
  2397. }
  2398. /**
  2399. * i40e_aq_get_cee_dcb_config
  2400. * @hw: pointer to the hw struct
  2401. * @buff: response buffer that stores CEE operational configuration
  2402. * @buff_size: size of the buffer passed
  2403. * @cmd_details: pointer to command details structure or NULL
  2404. *
  2405. * Get CEE DCBX mode operational configuration from firmware
  2406. **/
  2407. i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
  2408. void *buff, u16 buff_size,
  2409. struct i40e_asq_cmd_details *cmd_details)
  2410. {
  2411. struct i40e_aq_desc desc;
  2412. i40e_status status;
  2413. if (buff_size == 0 || !buff)
  2414. return I40E_ERR_PARAM;
  2415. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
  2416. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2417. status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
  2418. cmd_details);
  2419. return status;
  2420. }
  2421. /**
  2422. * i40e_aq_add_udp_tunnel
  2423. * @hw: pointer to the hw struct
  2424. * @udp_port: the UDP port to add
  2425. * @header_len: length of the tunneling header length in DWords
  2426. * @protocol_index: protocol index type
  2427. * @filter_index: pointer to filter index
  2428. * @cmd_details: pointer to command details structure or NULL
  2429. **/
  2430. i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
  2431. u16 udp_port, u8 protocol_index,
  2432. u8 *filter_index,
  2433. struct i40e_asq_cmd_details *cmd_details)
  2434. {
  2435. struct i40e_aq_desc desc;
  2436. struct i40e_aqc_add_udp_tunnel *cmd =
  2437. (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
  2438. struct i40e_aqc_del_udp_tunnel_completion *resp =
  2439. (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
  2440. i40e_status status;
  2441. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
  2442. cmd->udp_port = cpu_to_le16(udp_port);
  2443. cmd->protocol_type = protocol_index;
  2444. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2445. if (!status)
  2446. *filter_index = resp->index;
  2447. return status;
  2448. }
  2449. /**
  2450. * i40e_aq_del_udp_tunnel
  2451. * @hw: pointer to the hw struct
  2452. * @index: filter index
  2453. * @cmd_details: pointer to command details structure or NULL
  2454. **/
  2455. i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
  2456. struct i40e_asq_cmd_details *cmd_details)
  2457. {
  2458. struct i40e_aq_desc desc;
  2459. struct i40e_aqc_remove_udp_tunnel *cmd =
  2460. (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
  2461. i40e_status status;
  2462. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
  2463. cmd->index = index;
  2464. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2465. return status;
  2466. }
  2467. /**
  2468. * i40e_aq_delete_element - Delete switch element
  2469. * @hw: pointer to the hw struct
  2470. * @seid: the SEID to delete from the switch
  2471. * @cmd_details: pointer to command details structure or NULL
  2472. *
  2473. * This deletes a switch element from the switch.
  2474. **/
  2475. i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
  2476. struct i40e_asq_cmd_details *cmd_details)
  2477. {
  2478. struct i40e_aq_desc desc;
  2479. struct i40e_aqc_switch_seid *cmd =
  2480. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  2481. i40e_status status;
  2482. if (seid == 0)
  2483. return I40E_ERR_PARAM;
  2484. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
  2485. cmd->seid = cpu_to_le16(seid);
  2486. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2487. return status;
  2488. }
  2489. /**
  2490. * i40e_aq_dcb_updated - DCB Updated Command
  2491. * @hw: pointer to the hw struct
  2492. * @cmd_details: pointer to command details structure or NULL
  2493. *
  2494. * EMP will return when the shared RPB settings have been
  2495. * recomputed and modified. The retval field in the descriptor
  2496. * will be set to 0 when RPB is modified.
  2497. **/
  2498. i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
  2499. struct i40e_asq_cmd_details *cmd_details)
  2500. {
  2501. struct i40e_aq_desc desc;
  2502. i40e_status status;
  2503. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
  2504. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2505. return status;
  2506. }
  2507. /**
  2508. * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
  2509. * @hw: pointer to the hw struct
  2510. * @seid: seid for the physical port/switching component/vsi
  2511. * @buff: Indirect buffer to hold data parameters and response
  2512. * @buff_size: Indirect buffer size
  2513. * @opcode: Tx scheduler AQ command opcode
  2514. * @cmd_details: pointer to command details structure or NULL
  2515. *
  2516. * Generic command handler for Tx scheduler AQ commands
  2517. **/
  2518. static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
  2519. void *buff, u16 buff_size,
  2520. enum i40e_admin_queue_opc opcode,
  2521. struct i40e_asq_cmd_details *cmd_details)
  2522. {
  2523. struct i40e_aq_desc desc;
  2524. struct i40e_aqc_tx_sched_ind *cmd =
  2525. (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
  2526. i40e_status status;
  2527. bool cmd_param_flag = false;
  2528. switch (opcode) {
  2529. case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
  2530. case i40e_aqc_opc_configure_vsi_tc_bw:
  2531. case i40e_aqc_opc_enable_switching_comp_ets:
  2532. case i40e_aqc_opc_modify_switching_comp_ets:
  2533. case i40e_aqc_opc_disable_switching_comp_ets:
  2534. case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
  2535. case i40e_aqc_opc_configure_switching_comp_bw_config:
  2536. cmd_param_flag = true;
  2537. break;
  2538. case i40e_aqc_opc_query_vsi_bw_config:
  2539. case i40e_aqc_opc_query_vsi_ets_sla_config:
  2540. case i40e_aqc_opc_query_switching_comp_ets_config:
  2541. case i40e_aqc_opc_query_port_ets_config:
  2542. case i40e_aqc_opc_query_switching_comp_bw_config:
  2543. cmd_param_flag = false;
  2544. break;
  2545. default:
  2546. return I40E_ERR_PARAM;
  2547. }
  2548. i40e_fill_default_direct_cmd_desc(&desc, opcode);
  2549. /* Indirect command */
  2550. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2551. if (cmd_param_flag)
  2552. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  2553. if (buff_size > I40E_AQ_LARGE_BUF)
  2554. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2555. desc.datalen = cpu_to_le16(buff_size);
  2556. cmd->vsi_seid = cpu_to_le16(seid);
  2557. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2558. return status;
  2559. }
  2560. /**
  2561. * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
  2562. * @hw: pointer to the hw struct
  2563. * @seid: VSI seid
  2564. * @credit: BW limit credits (0 = disabled)
  2565. * @max_credit: Max BW limit credits
  2566. * @cmd_details: pointer to command details structure or NULL
  2567. **/
  2568. i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
  2569. u16 seid, u16 credit, u8 max_credit,
  2570. struct i40e_asq_cmd_details *cmd_details)
  2571. {
  2572. struct i40e_aq_desc desc;
  2573. struct i40e_aqc_configure_vsi_bw_limit *cmd =
  2574. (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
  2575. i40e_status status;
  2576. i40e_fill_default_direct_cmd_desc(&desc,
  2577. i40e_aqc_opc_configure_vsi_bw_limit);
  2578. cmd->vsi_seid = cpu_to_le16(seid);
  2579. cmd->credit = cpu_to_le16(credit);
  2580. cmd->max_credit = max_credit;
  2581. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2582. return status;
  2583. }
  2584. /**
  2585. * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
  2586. * @hw: pointer to the hw struct
  2587. * @seid: VSI seid
  2588. * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
  2589. * @cmd_details: pointer to command details structure or NULL
  2590. **/
  2591. i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
  2592. u16 seid,
  2593. struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
  2594. struct i40e_asq_cmd_details *cmd_details)
  2595. {
  2596. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2597. i40e_aqc_opc_configure_vsi_tc_bw,
  2598. cmd_details);
  2599. }
  2600. /**
  2601. * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
  2602. * @hw: pointer to the hw struct
  2603. * @seid: seid of the switching component connected to Physical Port
  2604. * @ets_data: Buffer holding ETS parameters
  2605. * @cmd_details: pointer to command details structure or NULL
  2606. **/
  2607. i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
  2608. u16 seid,
  2609. struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
  2610. enum i40e_admin_queue_opc opcode,
  2611. struct i40e_asq_cmd_details *cmd_details)
  2612. {
  2613. return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
  2614. sizeof(*ets_data), opcode, cmd_details);
  2615. }
  2616. /**
  2617. * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
  2618. * @hw: pointer to the hw struct
  2619. * @seid: seid of the switching component
  2620. * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
  2621. * @cmd_details: pointer to command details structure or NULL
  2622. **/
  2623. i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
  2624. u16 seid,
  2625. struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
  2626. struct i40e_asq_cmd_details *cmd_details)
  2627. {
  2628. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2629. i40e_aqc_opc_configure_switching_comp_bw_config,
  2630. cmd_details);
  2631. }
  2632. /**
  2633. * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
  2634. * @hw: pointer to the hw struct
  2635. * @seid: seid of the VSI
  2636. * @bw_data: Buffer to hold VSI BW configuration
  2637. * @cmd_details: pointer to command details structure or NULL
  2638. **/
  2639. i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
  2640. u16 seid,
  2641. struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
  2642. struct i40e_asq_cmd_details *cmd_details)
  2643. {
  2644. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2645. i40e_aqc_opc_query_vsi_bw_config,
  2646. cmd_details);
  2647. }
  2648. /**
  2649. * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
  2650. * @hw: pointer to the hw struct
  2651. * @seid: seid of the VSI
  2652. * @bw_data: Buffer to hold VSI BW configuration per TC
  2653. * @cmd_details: pointer to command details structure or NULL
  2654. **/
  2655. i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
  2656. u16 seid,
  2657. struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
  2658. struct i40e_asq_cmd_details *cmd_details)
  2659. {
  2660. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2661. i40e_aqc_opc_query_vsi_ets_sla_config,
  2662. cmd_details);
  2663. }
  2664. /**
  2665. * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
  2666. * @hw: pointer to the hw struct
  2667. * @seid: seid of the switching component
  2668. * @bw_data: Buffer to hold switching component's per TC BW config
  2669. * @cmd_details: pointer to command details structure or NULL
  2670. **/
  2671. i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
  2672. u16 seid,
  2673. struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
  2674. struct i40e_asq_cmd_details *cmd_details)
  2675. {
  2676. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2677. i40e_aqc_opc_query_switching_comp_ets_config,
  2678. cmd_details);
  2679. }
  2680. /**
  2681. * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
  2682. * @hw: pointer to the hw struct
  2683. * @seid: seid of the VSI or switching component connected to Physical Port
  2684. * @bw_data: Buffer to hold current ETS configuration for the Physical Port
  2685. * @cmd_details: pointer to command details structure or NULL
  2686. **/
  2687. i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
  2688. u16 seid,
  2689. struct i40e_aqc_query_port_ets_config_resp *bw_data,
  2690. struct i40e_asq_cmd_details *cmd_details)
  2691. {
  2692. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2693. i40e_aqc_opc_query_port_ets_config,
  2694. cmd_details);
  2695. }
  2696. /**
  2697. * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
  2698. * @hw: pointer to the hw struct
  2699. * @seid: seid of the switching component
  2700. * @bw_data: Buffer to hold switching component's BW configuration
  2701. * @cmd_details: pointer to command details structure or NULL
  2702. **/
  2703. i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
  2704. u16 seid,
  2705. struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
  2706. struct i40e_asq_cmd_details *cmd_details)
  2707. {
  2708. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2709. i40e_aqc_opc_query_switching_comp_bw_config,
  2710. cmd_details);
  2711. }
  2712. /**
  2713. * i40e_validate_filter_settings
  2714. * @hw: pointer to the hardware structure
  2715. * @settings: Filter control settings
  2716. *
  2717. * Check and validate the filter control settings passed.
  2718. * The function checks for the valid filter/context sizes being
  2719. * passed for FCoE and PE.
  2720. *
  2721. * Returns 0 if the values passed are valid and within
  2722. * range else returns an error.
  2723. **/
  2724. static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
  2725. struct i40e_filter_control_settings *settings)
  2726. {
  2727. u32 fcoe_cntx_size, fcoe_filt_size;
  2728. u32 pe_cntx_size, pe_filt_size;
  2729. u32 fcoe_fmax;
  2730. u32 val;
  2731. /* Validate FCoE settings passed */
  2732. switch (settings->fcoe_filt_num) {
  2733. case I40E_HASH_FILTER_SIZE_1K:
  2734. case I40E_HASH_FILTER_SIZE_2K:
  2735. case I40E_HASH_FILTER_SIZE_4K:
  2736. case I40E_HASH_FILTER_SIZE_8K:
  2737. case I40E_HASH_FILTER_SIZE_16K:
  2738. case I40E_HASH_FILTER_SIZE_32K:
  2739. fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  2740. fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
  2741. break;
  2742. default:
  2743. return I40E_ERR_PARAM;
  2744. }
  2745. switch (settings->fcoe_cntx_num) {
  2746. case I40E_DMA_CNTX_SIZE_512:
  2747. case I40E_DMA_CNTX_SIZE_1K:
  2748. case I40E_DMA_CNTX_SIZE_2K:
  2749. case I40E_DMA_CNTX_SIZE_4K:
  2750. fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  2751. fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
  2752. break;
  2753. default:
  2754. return I40E_ERR_PARAM;
  2755. }
  2756. /* Validate PE settings passed */
  2757. switch (settings->pe_filt_num) {
  2758. case I40E_HASH_FILTER_SIZE_1K:
  2759. case I40E_HASH_FILTER_SIZE_2K:
  2760. case I40E_HASH_FILTER_SIZE_4K:
  2761. case I40E_HASH_FILTER_SIZE_8K:
  2762. case I40E_HASH_FILTER_SIZE_16K:
  2763. case I40E_HASH_FILTER_SIZE_32K:
  2764. case I40E_HASH_FILTER_SIZE_64K:
  2765. case I40E_HASH_FILTER_SIZE_128K:
  2766. case I40E_HASH_FILTER_SIZE_256K:
  2767. case I40E_HASH_FILTER_SIZE_512K:
  2768. case I40E_HASH_FILTER_SIZE_1M:
  2769. pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  2770. pe_filt_size <<= (u32)settings->pe_filt_num;
  2771. break;
  2772. default:
  2773. return I40E_ERR_PARAM;
  2774. }
  2775. switch (settings->pe_cntx_num) {
  2776. case I40E_DMA_CNTX_SIZE_512:
  2777. case I40E_DMA_CNTX_SIZE_1K:
  2778. case I40E_DMA_CNTX_SIZE_2K:
  2779. case I40E_DMA_CNTX_SIZE_4K:
  2780. case I40E_DMA_CNTX_SIZE_8K:
  2781. case I40E_DMA_CNTX_SIZE_16K:
  2782. case I40E_DMA_CNTX_SIZE_32K:
  2783. case I40E_DMA_CNTX_SIZE_64K:
  2784. case I40E_DMA_CNTX_SIZE_128K:
  2785. case I40E_DMA_CNTX_SIZE_256K:
  2786. pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  2787. pe_cntx_size <<= (u32)settings->pe_cntx_num;
  2788. break;
  2789. default:
  2790. return I40E_ERR_PARAM;
  2791. }
  2792. /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
  2793. val = rd32(hw, I40E_GLHMC_FCOEFMAX);
  2794. fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
  2795. >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
  2796. if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
  2797. return I40E_ERR_INVALID_SIZE;
  2798. return 0;
  2799. }
  2800. /**
  2801. * i40e_set_filter_control
  2802. * @hw: pointer to the hardware structure
  2803. * @settings: Filter control settings
  2804. *
  2805. * Set the Queue Filters for PE/FCoE and enable filters required
  2806. * for a single PF. It is expected that these settings are programmed
  2807. * at the driver initialization time.
  2808. **/
  2809. i40e_status i40e_set_filter_control(struct i40e_hw *hw,
  2810. struct i40e_filter_control_settings *settings)
  2811. {
  2812. i40e_status ret = 0;
  2813. u32 hash_lut_size = 0;
  2814. u32 val;
  2815. if (!settings)
  2816. return I40E_ERR_PARAM;
  2817. /* Validate the input settings */
  2818. ret = i40e_validate_filter_settings(hw, settings);
  2819. if (ret)
  2820. return ret;
  2821. /* Read the PF Queue Filter control register */
  2822. val = rd32(hw, I40E_PFQF_CTL_0);
  2823. /* Program required PE hash buckets for the PF */
  2824. val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
  2825. val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
  2826. I40E_PFQF_CTL_0_PEHSIZE_MASK;
  2827. /* Program required PE contexts for the PF */
  2828. val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
  2829. val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
  2830. I40E_PFQF_CTL_0_PEDSIZE_MASK;
  2831. /* Program required FCoE hash buckets for the PF */
  2832. val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  2833. val |= ((u32)settings->fcoe_filt_num <<
  2834. I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
  2835. I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  2836. /* Program required FCoE DDP contexts for the PF */
  2837. val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  2838. val |= ((u32)settings->fcoe_cntx_num <<
  2839. I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
  2840. I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  2841. /* Program Hash LUT size for the PF */
  2842. val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  2843. if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
  2844. hash_lut_size = 1;
  2845. val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
  2846. I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  2847. /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
  2848. if (settings->enable_fdir)
  2849. val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
  2850. if (settings->enable_ethtype)
  2851. val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
  2852. if (settings->enable_macvlan)
  2853. val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
  2854. wr32(hw, I40E_PFQF_CTL_0, val);
  2855. return 0;
  2856. }
  2857. /**
  2858. * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
  2859. * @hw: pointer to the hw struct
  2860. * @mac_addr: MAC address to use in the filter
  2861. * @ethtype: Ethertype to use in the filter
  2862. * @flags: Flags that needs to be applied to the filter
  2863. * @vsi_seid: seid of the control VSI
  2864. * @queue: VSI queue number to send the packet to
  2865. * @is_add: Add control packet filter if True else remove
  2866. * @stats: Structure to hold information on control filter counts
  2867. * @cmd_details: pointer to command details structure or NULL
  2868. *
  2869. * This command will Add or Remove control packet filter for a control VSI.
  2870. * In return it will update the total number of perfect filter count in
  2871. * the stats member.
  2872. **/
  2873. i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
  2874. u8 *mac_addr, u16 ethtype, u16 flags,
  2875. u16 vsi_seid, u16 queue, bool is_add,
  2876. struct i40e_control_filter_stats *stats,
  2877. struct i40e_asq_cmd_details *cmd_details)
  2878. {
  2879. struct i40e_aq_desc desc;
  2880. struct i40e_aqc_add_remove_control_packet_filter *cmd =
  2881. (struct i40e_aqc_add_remove_control_packet_filter *)
  2882. &desc.params.raw;
  2883. struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
  2884. (struct i40e_aqc_add_remove_control_packet_filter_completion *)
  2885. &desc.params.raw;
  2886. i40e_status status;
  2887. if (vsi_seid == 0)
  2888. return I40E_ERR_PARAM;
  2889. if (is_add) {
  2890. i40e_fill_default_direct_cmd_desc(&desc,
  2891. i40e_aqc_opc_add_control_packet_filter);
  2892. cmd->queue = cpu_to_le16(queue);
  2893. } else {
  2894. i40e_fill_default_direct_cmd_desc(&desc,
  2895. i40e_aqc_opc_remove_control_packet_filter);
  2896. }
  2897. if (mac_addr)
  2898. memcpy(cmd->mac, mac_addr, ETH_ALEN);
  2899. cmd->etype = cpu_to_le16(ethtype);
  2900. cmd->flags = cpu_to_le16(flags);
  2901. cmd->seid = cpu_to_le16(vsi_seid);
  2902. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2903. if (!status && stats) {
  2904. stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
  2905. stats->etype_used = le16_to_cpu(resp->etype_used);
  2906. stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
  2907. stats->etype_free = le16_to_cpu(resp->etype_free);
  2908. }
  2909. return status;
  2910. }
  2911. /**
  2912. * i40e_aq_alternate_read
  2913. * @hw: pointer to the hardware structure
  2914. * @reg_addr0: address of first dword to be read
  2915. * @reg_val0: pointer for data read from 'reg_addr0'
  2916. * @reg_addr1: address of second dword to be read
  2917. * @reg_val1: pointer for data read from 'reg_addr1'
  2918. *
  2919. * Read one or two dwords from alternate structure. Fields are indicated
  2920. * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
  2921. * is not passed then only register at 'reg_addr0' is read.
  2922. *
  2923. **/
  2924. i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
  2925. u32 reg_addr0, u32 *reg_val0,
  2926. u32 reg_addr1, u32 *reg_val1)
  2927. {
  2928. struct i40e_aq_desc desc;
  2929. struct i40e_aqc_alternate_write *cmd_resp =
  2930. (struct i40e_aqc_alternate_write *)&desc.params.raw;
  2931. i40e_status status;
  2932. if (!reg_val0)
  2933. return I40E_ERR_PARAM;
  2934. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
  2935. cmd_resp->address0 = cpu_to_le32(reg_addr0);
  2936. cmd_resp->address1 = cpu_to_le32(reg_addr1);
  2937. status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
  2938. if (!status) {
  2939. *reg_val0 = le32_to_cpu(cmd_resp->data0);
  2940. if (reg_val1)
  2941. *reg_val1 = le32_to_cpu(cmd_resp->data1);
  2942. }
  2943. return status;
  2944. }
  2945. /**
  2946. * i40e_aq_resume_port_tx
  2947. * @hw: pointer to the hardware structure
  2948. * @cmd_details: pointer to command details structure or NULL
  2949. *
  2950. * Resume port's Tx traffic
  2951. **/
  2952. i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
  2953. struct i40e_asq_cmd_details *cmd_details)
  2954. {
  2955. struct i40e_aq_desc desc;
  2956. i40e_status status;
  2957. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
  2958. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2959. return status;
  2960. }
  2961. /**
  2962. * i40e_set_pci_config_data - store PCI bus info
  2963. * @hw: pointer to hardware structure
  2964. * @link_status: the link status word from PCI config space
  2965. *
  2966. * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
  2967. **/
  2968. void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
  2969. {
  2970. hw->bus.type = i40e_bus_type_pci_express;
  2971. switch (link_status & PCI_EXP_LNKSTA_NLW) {
  2972. case PCI_EXP_LNKSTA_NLW_X1:
  2973. hw->bus.width = i40e_bus_width_pcie_x1;
  2974. break;
  2975. case PCI_EXP_LNKSTA_NLW_X2:
  2976. hw->bus.width = i40e_bus_width_pcie_x2;
  2977. break;
  2978. case PCI_EXP_LNKSTA_NLW_X4:
  2979. hw->bus.width = i40e_bus_width_pcie_x4;
  2980. break;
  2981. case PCI_EXP_LNKSTA_NLW_X8:
  2982. hw->bus.width = i40e_bus_width_pcie_x8;
  2983. break;
  2984. default:
  2985. hw->bus.width = i40e_bus_width_unknown;
  2986. break;
  2987. }
  2988. switch (link_status & PCI_EXP_LNKSTA_CLS) {
  2989. case PCI_EXP_LNKSTA_CLS_2_5GB:
  2990. hw->bus.speed = i40e_bus_speed_2500;
  2991. break;
  2992. case PCI_EXP_LNKSTA_CLS_5_0GB:
  2993. hw->bus.speed = i40e_bus_speed_5000;
  2994. break;
  2995. case PCI_EXP_LNKSTA_CLS_8_0GB:
  2996. hw->bus.speed = i40e_bus_speed_8000;
  2997. break;
  2998. default:
  2999. hw->bus.speed = i40e_bus_speed_unknown;
  3000. break;
  3001. }
  3002. }
  3003. /**
  3004. * i40e_read_bw_from_alt_ram
  3005. * @hw: pointer to the hardware structure
  3006. * @max_bw: pointer for max_bw read
  3007. * @min_bw: pointer for min_bw read
  3008. * @min_valid: pointer for bool that is true if min_bw is a valid value
  3009. * @max_valid: pointer for bool that is true if max_bw is a valid value
  3010. *
  3011. * Read bw from the alternate ram for the given pf
  3012. **/
  3013. i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
  3014. u32 *max_bw, u32 *min_bw,
  3015. bool *min_valid, bool *max_valid)
  3016. {
  3017. i40e_status status;
  3018. u32 max_bw_addr, min_bw_addr;
  3019. /* Calculate the address of the min/max bw registers */
  3020. max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
  3021. I40E_ALT_STRUCT_MAX_BW_OFFSET +
  3022. (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
  3023. min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
  3024. I40E_ALT_STRUCT_MIN_BW_OFFSET +
  3025. (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
  3026. /* Read the bandwidths from alt ram */
  3027. status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
  3028. min_bw_addr, min_bw);
  3029. if (*min_bw & I40E_ALT_BW_VALID_MASK)
  3030. *min_valid = true;
  3031. else
  3032. *min_valid = false;
  3033. if (*max_bw & I40E_ALT_BW_VALID_MASK)
  3034. *max_valid = true;
  3035. else
  3036. *max_valid = false;
  3037. return status;
  3038. }
  3039. /**
  3040. * i40e_aq_configure_partition_bw
  3041. * @hw: pointer to the hardware structure
  3042. * @bw_data: Buffer holding valid pfs and bw limits
  3043. * @cmd_details: pointer to command details
  3044. *
  3045. * Configure partitions guaranteed/max bw
  3046. **/
  3047. i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
  3048. struct i40e_aqc_configure_partition_bw_data *bw_data,
  3049. struct i40e_asq_cmd_details *cmd_details)
  3050. {
  3051. i40e_status status;
  3052. struct i40e_aq_desc desc;
  3053. u16 bwd_size = sizeof(*bw_data);
  3054. i40e_fill_default_direct_cmd_desc(&desc,
  3055. i40e_aqc_opc_configure_partition_bw);
  3056. /* Indirect command */
  3057. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3058. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  3059. if (bwd_size > I40E_AQ_LARGE_BUF)
  3060. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  3061. desc.datalen = cpu_to_le16(bwd_size);
  3062. status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
  3063. cmd_details);
  3064. return status;
  3065. }