i40e_common.c 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644
  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. case I40E_DEV_ID_20G_KR2:
  52. hw->mac.type = I40E_MAC_XL710;
  53. break;
  54. case I40E_DEV_ID_VF:
  55. case I40E_DEV_ID_VF_HV:
  56. hw->mac.type = I40E_MAC_VF;
  57. break;
  58. default:
  59. hw->mac.type = I40E_MAC_GENERIC;
  60. break;
  61. }
  62. } else {
  63. status = I40E_ERR_DEVICE_NOT_SUPPORTED;
  64. }
  65. hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
  66. hw->mac.type, status);
  67. return status;
  68. }
  69. /**
  70. * i40e_debug_aq
  71. * @hw: debug mask related to admin queue
  72. * @mask: debug mask
  73. * @desc: pointer to admin queue descriptor
  74. * @buffer: pointer to command buffer
  75. * @buf_len: max length of buffer
  76. *
  77. * Dumps debug log about adminq command with descriptor contents.
  78. **/
  79. void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
  80. void *buffer, u16 buf_len)
  81. {
  82. struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
  83. u16 len = le16_to_cpu(aq_desc->datalen);
  84. u8 *buf = (u8 *)buffer;
  85. u16 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. i40e_debug(hw, mask, "AQ CMD Buffer:\n");
  105. if (buf_len < len)
  106. len = buf_len;
  107. /* write the full 16-byte chunks */
  108. for (i = 0; i < (len - 16); i += 16)
  109. i40e_debug(hw, mask,
  110. "\t0x%04X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  111. i, buf[i], buf[i + 1], buf[i + 2],
  112. buf[i + 3], buf[i + 4], buf[i + 5],
  113. buf[i + 6], buf[i + 7], buf[i + 8],
  114. buf[i + 9], buf[i + 10], buf[i + 11],
  115. buf[i + 12], buf[i + 13], buf[i + 14],
  116. buf[i + 15]);
  117. /* write whatever's left over without overrunning the buffer */
  118. if (i < len) {
  119. char d_buf[80];
  120. int j = 0;
  121. memset(d_buf, 0, sizeof(d_buf));
  122. j += sprintf(d_buf, "\t0x%04X ", i);
  123. while (i < len)
  124. j += sprintf(&d_buf[j], " %02X", buf[i++]);
  125. i40e_debug(hw, mask, "%s\n", d_buf);
  126. }
  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. case I40E_PHY_TYPE_40GBASE_AOC:
  743. case I40E_PHY_TYPE_10GBASE_AOC:
  744. media = I40E_MEDIA_TYPE_DA;
  745. break;
  746. case I40E_PHY_TYPE_1000BASE_KX:
  747. case I40E_PHY_TYPE_10GBASE_KX4:
  748. case I40E_PHY_TYPE_10GBASE_KR:
  749. case I40E_PHY_TYPE_40GBASE_KR4:
  750. case I40E_PHY_TYPE_20GBASE_KR2:
  751. media = I40E_MEDIA_TYPE_BACKPLANE;
  752. break;
  753. case I40E_PHY_TYPE_SGMII:
  754. case I40E_PHY_TYPE_XAUI:
  755. case I40E_PHY_TYPE_XFI:
  756. case I40E_PHY_TYPE_XLAUI:
  757. case I40E_PHY_TYPE_XLPPI:
  758. default:
  759. media = I40E_MEDIA_TYPE_UNKNOWN;
  760. break;
  761. }
  762. return media;
  763. }
  764. #define I40E_PF_RESET_WAIT_COUNT_A0 200
  765. #define I40E_PF_RESET_WAIT_COUNT 200
  766. /**
  767. * i40e_pf_reset - Reset the PF
  768. * @hw: pointer to the hardware structure
  769. *
  770. * Assuming someone else has triggered a global reset,
  771. * assure the global reset is complete and then reset the PF
  772. **/
  773. i40e_status i40e_pf_reset(struct i40e_hw *hw)
  774. {
  775. u32 cnt = 0;
  776. u32 cnt1 = 0;
  777. u32 reg = 0;
  778. u32 grst_del;
  779. /* Poll for Global Reset steady state in case of recent GRST.
  780. * The grst delay value is in 100ms units, and we'll wait a
  781. * couple counts longer to be sure we don't just miss the end.
  782. */
  783. grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
  784. I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
  785. I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
  786. for (cnt = 0; cnt < grst_del + 2; cnt++) {
  787. reg = rd32(hw, I40E_GLGEN_RSTAT);
  788. if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
  789. break;
  790. msleep(100);
  791. }
  792. if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
  793. hw_dbg(hw, "Global reset polling failed to complete.\n");
  794. return I40E_ERR_RESET_FAILED;
  795. }
  796. /* Now Wait for the FW to be ready */
  797. for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
  798. reg = rd32(hw, I40E_GLNVM_ULD);
  799. reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  800. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
  801. if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  802. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
  803. hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
  804. break;
  805. }
  806. usleep_range(10000, 20000);
  807. }
  808. if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  809. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
  810. hw_dbg(hw, "wait for FW Reset complete timedout\n");
  811. hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
  812. return I40E_ERR_RESET_FAILED;
  813. }
  814. /* If there was a Global Reset in progress when we got here,
  815. * we don't need to do the PF Reset
  816. */
  817. if (!cnt) {
  818. if (hw->revision_id == 0)
  819. cnt = I40E_PF_RESET_WAIT_COUNT_A0;
  820. else
  821. cnt = I40E_PF_RESET_WAIT_COUNT;
  822. reg = rd32(hw, I40E_PFGEN_CTRL);
  823. wr32(hw, I40E_PFGEN_CTRL,
  824. (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
  825. for (; cnt; cnt--) {
  826. reg = rd32(hw, I40E_PFGEN_CTRL);
  827. if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
  828. break;
  829. usleep_range(1000, 2000);
  830. }
  831. if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
  832. hw_dbg(hw, "PF reset polling failed to complete.\n");
  833. return I40E_ERR_RESET_FAILED;
  834. }
  835. }
  836. i40e_clear_pxe_mode(hw);
  837. return 0;
  838. }
  839. /**
  840. * i40e_clear_hw - clear out any left over hw state
  841. * @hw: pointer to the hw struct
  842. *
  843. * Clear queues and interrupts, typically called at init time,
  844. * but after the capabilities have been found so we know how many
  845. * queues and msix vectors have been allocated.
  846. **/
  847. void i40e_clear_hw(struct i40e_hw *hw)
  848. {
  849. u32 num_queues, base_queue;
  850. u32 num_pf_int;
  851. u32 num_vf_int;
  852. u32 num_vfs;
  853. u32 i, j;
  854. u32 val;
  855. u32 eol = 0x7ff;
  856. /* get number of interrupts, queues, and VFs */
  857. val = rd32(hw, I40E_GLPCI_CNF2);
  858. num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
  859. I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
  860. num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
  861. I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
  862. val = rd32(hw, I40E_PFLAN_QALLOC);
  863. base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
  864. I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
  865. j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
  866. I40E_PFLAN_QALLOC_LASTQ_SHIFT;
  867. if (val & I40E_PFLAN_QALLOC_VALID_MASK)
  868. num_queues = (j - base_queue) + 1;
  869. else
  870. num_queues = 0;
  871. val = rd32(hw, I40E_PF_VT_PFALLOC);
  872. i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
  873. I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
  874. j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
  875. I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
  876. if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
  877. num_vfs = (j - i) + 1;
  878. else
  879. num_vfs = 0;
  880. /* stop all the interrupts */
  881. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  882. val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
  883. for (i = 0; i < num_pf_int - 2; i++)
  884. wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
  885. /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
  886. val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  887. wr32(hw, I40E_PFINT_LNKLST0, val);
  888. for (i = 0; i < num_pf_int - 2; i++)
  889. wr32(hw, I40E_PFINT_LNKLSTN(i), val);
  890. val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  891. for (i = 0; i < num_vfs; i++)
  892. wr32(hw, I40E_VPINT_LNKLST0(i), val);
  893. for (i = 0; i < num_vf_int - 2; i++)
  894. wr32(hw, I40E_VPINT_LNKLSTN(i), val);
  895. /* warn the HW of the coming Tx disables */
  896. for (i = 0; i < num_queues; i++) {
  897. u32 abs_queue_idx = base_queue + i;
  898. u32 reg_block = 0;
  899. if (abs_queue_idx >= 128) {
  900. reg_block = abs_queue_idx / 128;
  901. abs_queue_idx %= 128;
  902. }
  903. val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
  904. val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
  905. val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
  906. val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
  907. wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
  908. }
  909. udelay(400);
  910. /* stop all the queues */
  911. for (i = 0; i < num_queues; i++) {
  912. wr32(hw, I40E_QINT_TQCTL(i), 0);
  913. wr32(hw, I40E_QTX_ENA(i), 0);
  914. wr32(hw, I40E_QINT_RQCTL(i), 0);
  915. wr32(hw, I40E_QRX_ENA(i), 0);
  916. }
  917. /* short wait for all queue disables to settle */
  918. udelay(50);
  919. }
  920. /**
  921. * i40e_clear_pxe_mode - clear pxe operations mode
  922. * @hw: pointer to the hw struct
  923. *
  924. * Make sure all PXE mode settings are cleared, including things
  925. * like descriptor fetch/write-back mode.
  926. **/
  927. void i40e_clear_pxe_mode(struct i40e_hw *hw)
  928. {
  929. u32 reg;
  930. if (i40e_check_asq_alive(hw))
  931. i40e_aq_clear_pxe_mode(hw, NULL);
  932. /* Clear single descriptor fetch/write-back mode */
  933. reg = rd32(hw, I40E_GLLAN_RCTL_0);
  934. if (hw->revision_id == 0) {
  935. /* As a work around clear PXE_MODE instead of setting it */
  936. wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
  937. } else {
  938. wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
  939. }
  940. }
  941. /**
  942. * i40e_led_is_mine - helper to find matching led
  943. * @hw: pointer to the hw struct
  944. * @idx: index into GPIO registers
  945. *
  946. * returns: 0 if no match, otherwise the value of the GPIO_CTL register
  947. */
  948. static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
  949. {
  950. u32 gpio_val = 0;
  951. u32 port;
  952. if (!hw->func_caps.led[idx])
  953. return 0;
  954. gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
  955. port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
  956. I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
  957. /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
  958. * if it is not our port then ignore
  959. */
  960. if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
  961. (port != hw->port))
  962. return 0;
  963. return gpio_val;
  964. }
  965. #define I40E_COMBINED_ACTIVITY 0xA
  966. #define I40E_FILTER_ACTIVITY 0xE
  967. #define I40E_LINK_ACTIVITY 0xC
  968. #define I40E_MAC_ACTIVITY 0xD
  969. #define I40E_LED0 22
  970. /**
  971. * i40e_led_get - return current on/off mode
  972. * @hw: pointer to the hw struct
  973. *
  974. * The value returned is the 'mode' field as defined in the
  975. * GPIO register definitions: 0x0 = off, 0xf = on, and other
  976. * values are variations of possible behaviors relating to
  977. * blink, link, and wire.
  978. **/
  979. u32 i40e_led_get(struct i40e_hw *hw)
  980. {
  981. u32 current_mode = 0;
  982. u32 mode = 0;
  983. int i;
  984. /* as per the documentation GPIO 22-29 are the LED
  985. * GPIO pins named LED0..LED7
  986. */
  987. for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
  988. u32 gpio_val = i40e_led_is_mine(hw, i);
  989. if (!gpio_val)
  990. continue;
  991. /* ignore gpio LED src mode entries related to the activity
  992. * LEDs
  993. */
  994. current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
  995. >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
  996. switch (current_mode) {
  997. case I40E_COMBINED_ACTIVITY:
  998. case I40E_FILTER_ACTIVITY:
  999. case I40E_MAC_ACTIVITY:
  1000. continue;
  1001. default:
  1002. break;
  1003. }
  1004. mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
  1005. I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
  1006. break;
  1007. }
  1008. return mode;
  1009. }
  1010. /**
  1011. * i40e_led_set - set new on/off mode
  1012. * @hw: pointer to the hw struct
  1013. * @mode: 0=off, 0xf=on (else see manual for mode details)
  1014. * @blink: true if the LED should blink when on, false if steady
  1015. *
  1016. * if this function is used to turn on the blink it should
  1017. * be used to disable the blink when restoring the original state.
  1018. **/
  1019. void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
  1020. {
  1021. u32 current_mode = 0;
  1022. int i;
  1023. if (mode & 0xfffffff0)
  1024. hw_dbg(hw, "invalid mode passed in %X\n", mode);
  1025. /* as per the documentation GPIO 22-29 are the LED
  1026. * GPIO pins named LED0..LED7
  1027. */
  1028. for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
  1029. u32 gpio_val = i40e_led_is_mine(hw, i);
  1030. if (!gpio_val)
  1031. continue;
  1032. /* ignore gpio LED src mode entries related to the activity
  1033. * LEDs
  1034. */
  1035. current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
  1036. >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
  1037. switch (current_mode) {
  1038. case I40E_COMBINED_ACTIVITY:
  1039. case I40E_FILTER_ACTIVITY:
  1040. case I40E_MAC_ACTIVITY:
  1041. continue;
  1042. default:
  1043. break;
  1044. }
  1045. gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
  1046. /* this & is a bit of paranoia, but serves as a range check */
  1047. gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
  1048. I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
  1049. if (mode == I40E_LINK_ACTIVITY)
  1050. blink = false;
  1051. if (blink)
  1052. gpio_val |= (1 << I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
  1053. else
  1054. gpio_val &= ~(1 << I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
  1055. wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
  1056. break;
  1057. }
  1058. }
  1059. /* Admin command wrappers */
  1060. /**
  1061. * i40e_aq_get_phy_capabilities
  1062. * @hw: pointer to the hw struct
  1063. * @abilities: structure for PHY capabilities to be filled
  1064. * @qualified_modules: report Qualified Modules
  1065. * @report_init: report init capabilities (active are default)
  1066. * @cmd_details: pointer to command details structure or NULL
  1067. *
  1068. * Returns the various PHY abilities supported on the Port.
  1069. **/
  1070. i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
  1071. bool qualified_modules, bool report_init,
  1072. struct i40e_aq_get_phy_abilities_resp *abilities,
  1073. struct i40e_asq_cmd_details *cmd_details)
  1074. {
  1075. struct i40e_aq_desc desc;
  1076. i40e_status status;
  1077. u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
  1078. if (!abilities)
  1079. return I40E_ERR_PARAM;
  1080. i40e_fill_default_direct_cmd_desc(&desc,
  1081. i40e_aqc_opc_get_phy_abilities);
  1082. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1083. if (abilities_size > I40E_AQ_LARGE_BUF)
  1084. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1085. if (qualified_modules)
  1086. desc.params.external.param0 |=
  1087. cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
  1088. if (report_init)
  1089. desc.params.external.param0 |=
  1090. cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
  1091. status = i40e_asq_send_command(hw, &desc, abilities, abilities_size,
  1092. cmd_details);
  1093. if (hw->aq.asq_last_status == I40E_AQ_RC_EIO)
  1094. status = I40E_ERR_UNKNOWN_PHY;
  1095. return status;
  1096. }
  1097. /**
  1098. * i40e_aq_set_phy_config
  1099. * @hw: pointer to the hw struct
  1100. * @config: structure with PHY configuration to be set
  1101. * @cmd_details: pointer to command details structure or NULL
  1102. *
  1103. * Set the various PHY configuration parameters
  1104. * supported on the Port.One or more of the Set PHY config parameters may be
  1105. * ignored in an MFP mode as the PF may not have the privilege to set some
  1106. * of the PHY Config parameters. This status will be indicated by the
  1107. * command response.
  1108. **/
  1109. enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
  1110. struct i40e_aq_set_phy_config *config,
  1111. struct i40e_asq_cmd_details *cmd_details)
  1112. {
  1113. struct i40e_aq_desc desc;
  1114. struct i40e_aq_set_phy_config *cmd =
  1115. (struct i40e_aq_set_phy_config *)&desc.params.raw;
  1116. enum i40e_status_code status;
  1117. if (!config)
  1118. return I40E_ERR_PARAM;
  1119. i40e_fill_default_direct_cmd_desc(&desc,
  1120. i40e_aqc_opc_set_phy_config);
  1121. *cmd = *config;
  1122. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1123. return status;
  1124. }
  1125. /**
  1126. * i40e_set_fc
  1127. * @hw: pointer to the hw struct
  1128. *
  1129. * Set the requested flow control mode using set_phy_config.
  1130. **/
  1131. enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
  1132. bool atomic_restart)
  1133. {
  1134. enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
  1135. struct i40e_aq_get_phy_abilities_resp abilities;
  1136. struct i40e_aq_set_phy_config config;
  1137. enum i40e_status_code status;
  1138. u8 pause_mask = 0x0;
  1139. *aq_failures = 0x0;
  1140. switch (fc_mode) {
  1141. case I40E_FC_FULL:
  1142. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
  1143. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
  1144. break;
  1145. case I40E_FC_RX_PAUSE:
  1146. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
  1147. break;
  1148. case I40E_FC_TX_PAUSE:
  1149. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
  1150. break;
  1151. default:
  1152. break;
  1153. }
  1154. /* Get the current phy config */
  1155. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  1156. NULL);
  1157. if (status) {
  1158. *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
  1159. return status;
  1160. }
  1161. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  1162. /* clear the old pause settings */
  1163. config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
  1164. ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
  1165. /* set the new abilities */
  1166. config.abilities |= pause_mask;
  1167. /* If the abilities have changed, then set the new config */
  1168. if (config.abilities != abilities.abilities) {
  1169. /* Auto restart link so settings take effect */
  1170. if (atomic_restart)
  1171. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  1172. /* Copy over all the old settings */
  1173. config.phy_type = abilities.phy_type;
  1174. config.link_speed = abilities.link_speed;
  1175. config.eee_capability = abilities.eee_capability;
  1176. config.eeer = abilities.eeer_val;
  1177. config.low_power_ctrl = abilities.d3_lpan;
  1178. status = i40e_aq_set_phy_config(hw, &config, NULL);
  1179. if (status)
  1180. *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
  1181. }
  1182. /* Update the link info */
  1183. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  1184. if (status) {
  1185. /* Wait a little bit (on 40G cards it sometimes takes a really
  1186. * long time for link to come back from the atomic reset)
  1187. * and try once more
  1188. */
  1189. msleep(1000);
  1190. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  1191. }
  1192. if (status)
  1193. *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
  1194. return status;
  1195. }
  1196. /**
  1197. * i40e_aq_clear_pxe_mode
  1198. * @hw: pointer to the hw struct
  1199. * @cmd_details: pointer to command details structure or NULL
  1200. *
  1201. * Tell the firmware that the driver is taking over from PXE
  1202. **/
  1203. i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
  1204. struct i40e_asq_cmd_details *cmd_details)
  1205. {
  1206. i40e_status status;
  1207. struct i40e_aq_desc desc;
  1208. struct i40e_aqc_clear_pxe *cmd =
  1209. (struct i40e_aqc_clear_pxe *)&desc.params.raw;
  1210. i40e_fill_default_direct_cmd_desc(&desc,
  1211. i40e_aqc_opc_clear_pxe_mode);
  1212. cmd->rx_cnt = 0x2;
  1213. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1214. wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
  1215. return status;
  1216. }
  1217. /**
  1218. * i40e_aq_set_link_restart_an
  1219. * @hw: pointer to the hw struct
  1220. * @enable_link: if true: enable link, if false: disable link
  1221. * @cmd_details: pointer to command details structure or NULL
  1222. *
  1223. * Sets up the link and restarts the Auto-Negotiation over the link.
  1224. **/
  1225. i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
  1226. bool enable_link,
  1227. struct i40e_asq_cmd_details *cmd_details)
  1228. {
  1229. struct i40e_aq_desc desc;
  1230. struct i40e_aqc_set_link_restart_an *cmd =
  1231. (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
  1232. i40e_status status;
  1233. i40e_fill_default_direct_cmd_desc(&desc,
  1234. i40e_aqc_opc_set_link_restart_an);
  1235. cmd->command = I40E_AQ_PHY_RESTART_AN;
  1236. if (enable_link)
  1237. cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
  1238. else
  1239. cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
  1240. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1241. return status;
  1242. }
  1243. /**
  1244. * i40e_aq_get_link_info
  1245. * @hw: pointer to the hw struct
  1246. * @enable_lse: enable/disable LinkStatusEvent reporting
  1247. * @link: pointer to link status structure - optional
  1248. * @cmd_details: pointer to command details structure or NULL
  1249. *
  1250. * Returns the link status of the adapter.
  1251. **/
  1252. i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
  1253. bool enable_lse, struct i40e_link_status *link,
  1254. struct i40e_asq_cmd_details *cmd_details)
  1255. {
  1256. struct i40e_aq_desc desc;
  1257. struct i40e_aqc_get_link_status *resp =
  1258. (struct i40e_aqc_get_link_status *)&desc.params.raw;
  1259. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  1260. i40e_status status;
  1261. bool tx_pause, rx_pause;
  1262. u16 command_flags;
  1263. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
  1264. if (enable_lse)
  1265. command_flags = I40E_AQ_LSE_ENABLE;
  1266. else
  1267. command_flags = I40E_AQ_LSE_DISABLE;
  1268. resp->command_flags = cpu_to_le16(command_flags);
  1269. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1270. if (status)
  1271. goto aq_get_link_info_exit;
  1272. /* save off old link status information */
  1273. hw->phy.link_info_old = *hw_link_info;
  1274. /* update link status */
  1275. hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
  1276. hw->phy.media_type = i40e_get_media_type(hw);
  1277. hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
  1278. hw_link_info->link_info = resp->link_info;
  1279. hw_link_info->an_info = resp->an_info;
  1280. hw_link_info->ext_info = resp->ext_info;
  1281. hw_link_info->loopback = resp->loopback;
  1282. hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
  1283. hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
  1284. /* update fc info */
  1285. tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
  1286. rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
  1287. if (tx_pause & rx_pause)
  1288. hw->fc.current_mode = I40E_FC_FULL;
  1289. else if (tx_pause)
  1290. hw->fc.current_mode = I40E_FC_TX_PAUSE;
  1291. else if (rx_pause)
  1292. hw->fc.current_mode = I40E_FC_RX_PAUSE;
  1293. else
  1294. hw->fc.current_mode = I40E_FC_NONE;
  1295. if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
  1296. hw_link_info->crc_enable = true;
  1297. else
  1298. hw_link_info->crc_enable = false;
  1299. if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE))
  1300. hw_link_info->lse_enable = true;
  1301. else
  1302. hw_link_info->lse_enable = false;
  1303. if ((hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
  1304. hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
  1305. hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
  1306. /* save link status information */
  1307. if (link)
  1308. *link = *hw_link_info;
  1309. /* flag cleared so helper functions don't call AQ again */
  1310. hw->phy.get_link_info = false;
  1311. aq_get_link_info_exit:
  1312. return status;
  1313. }
  1314. /**
  1315. * i40e_aq_set_phy_int_mask
  1316. * @hw: pointer to the hw struct
  1317. * @mask: interrupt mask to be set
  1318. * @cmd_details: pointer to command details structure or NULL
  1319. *
  1320. * Set link interrupt mask.
  1321. **/
  1322. i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
  1323. u16 mask,
  1324. struct i40e_asq_cmd_details *cmd_details)
  1325. {
  1326. struct i40e_aq_desc desc;
  1327. struct i40e_aqc_set_phy_int_mask *cmd =
  1328. (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
  1329. i40e_status status;
  1330. i40e_fill_default_direct_cmd_desc(&desc,
  1331. i40e_aqc_opc_set_phy_int_mask);
  1332. cmd->event_mask = cpu_to_le16(mask);
  1333. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1334. return status;
  1335. }
  1336. /**
  1337. * i40e_aq_add_vsi
  1338. * @hw: pointer to the hw struct
  1339. * @vsi_ctx: pointer to a vsi context struct
  1340. * @cmd_details: pointer to command details structure or NULL
  1341. *
  1342. * Add a VSI context to the hardware.
  1343. **/
  1344. i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
  1345. struct i40e_vsi_context *vsi_ctx,
  1346. struct i40e_asq_cmd_details *cmd_details)
  1347. {
  1348. struct i40e_aq_desc desc;
  1349. struct i40e_aqc_add_get_update_vsi *cmd =
  1350. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1351. struct i40e_aqc_add_get_update_vsi_completion *resp =
  1352. (struct i40e_aqc_add_get_update_vsi_completion *)
  1353. &desc.params.raw;
  1354. i40e_status status;
  1355. i40e_fill_default_direct_cmd_desc(&desc,
  1356. i40e_aqc_opc_add_vsi);
  1357. cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
  1358. cmd->connection_type = vsi_ctx->connection_type;
  1359. cmd->vf_id = vsi_ctx->vf_num;
  1360. cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
  1361. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1362. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1363. sizeof(vsi_ctx->info), cmd_details);
  1364. if (status)
  1365. goto aq_add_vsi_exit;
  1366. vsi_ctx->seid = le16_to_cpu(resp->seid);
  1367. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  1368. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  1369. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  1370. aq_add_vsi_exit:
  1371. return status;
  1372. }
  1373. /**
  1374. * i40e_aq_set_vsi_unicast_promiscuous
  1375. * @hw: pointer to the hw struct
  1376. * @seid: vsi number
  1377. * @set: set unicast promiscuous enable/disable
  1378. * @cmd_details: pointer to command details structure or NULL
  1379. **/
  1380. i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
  1381. u16 seid, bool set,
  1382. struct i40e_asq_cmd_details *cmd_details)
  1383. {
  1384. struct i40e_aq_desc desc;
  1385. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1386. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1387. i40e_status status;
  1388. u16 flags = 0;
  1389. i40e_fill_default_direct_cmd_desc(&desc,
  1390. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1391. if (set)
  1392. flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
  1393. cmd->promiscuous_flags = cpu_to_le16(flags);
  1394. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
  1395. cmd->seid = cpu_to_le16(seid);
  1396. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1397. return status;
  1398. }
  1399. /**
  1400. * i40e_aq_set_vsi_multicast_promiscuous
  1401. * @hw: pointer to the hw struct
  1402. * @seid: vsi number
  1403. * @set: set multicast promiscuous enable/disable
  1404. * @cmd_details: pointer to command details structure or NULL
  1405. **/
  1406. i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
  1407. u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
  1408. {
  1409. struct i40e_aq_desc desc;
  1410. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1411. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1412. i40e_status status;
  1413. u16 flags = 0;
  1414. i40e_fill_default_direct_cmd_desc(&desc,
  1415. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1416. if (set)
  1417. flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
  1418. cmd->promiscuous_flags = cpu_to_le16(flags);
  1419. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
  1420. cmd->seid = cpu_to_le16(seid);
  1421. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1422. return status;
  1423. }
  1424. /**
  1425. * i40e_aq_set_vsi_broadcast
  1426. * @hw: pointer to the hw struct
  1427. * @seid: vsi number
  1428. * @set_filter: true to set filter, false to clear filter
  1429. * @cmd_details: pointer to command details structure or NULL
  1430. *
  1431. * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
  1432. **/
  1433. i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
  1434. u16 seid, bool set_filter,
  1435. struct i40e_asq_cmd_details *cmd_details)
  1436. {
  1437. struct i40e_aq_desc desc;
  1438. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1439. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1440. i40e_status status;
  1441. i40e_fill_default_direct_cmd_desc(&desc,
  1442. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1443. if (set_filter)
  1444. cmd->promiscuous_flags
  1445. |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1446. else
  1447. cmd->promiscuous_flags
  1448. &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1449. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1450. cmd->seid = cpu_to_le16(seid);
  1451. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1452. return status;
  1453. }
  1454. /**
  1455. * i40e_get_vsi_params - get VSI configuration info
  1456. * @hw: pointer to the hw struct
  1457. * @vsi_ctx: pointer to a vsi context struct
  1458. * @cmd_details: pointer to command details structure or NULL
  1459. **/
  1460. i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
  1461. struct i40e_vsi_context *vsi_ctx,
  1462. struct i40e_asq_cmd_details *cmd_details)
  1463. {
  1464. struct i40e_aq_desc desc;
  1465. struct i40e_aqc_add_get_update_vsi *cmd =
  1466. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1467. struct i40e_aqc_add_get_update_vsi_completion *resp =
  1468. (struct i40e_aqc_add_get_update_vsi_completion *)
  1469. &desc.params.raw;
  1470. i40e_status status;
  1471. i40e_fill_default_direct_cmd_desc(&desc,
  1472. i40e_aqc_opc_get_vsi_parameters);
  1473. cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
  1474. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1475. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1476. sizeof(vsi_ctx->info), NULL);
  1477. if (status)
  1478. goto aq_get_vsi_params_exit;
  1479. vsi_ctx->seid = le16_to_cpu(resp->seid);
  1480. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  1481. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  1482. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  1483. aq_get_vsi_params_exit:
  1484. return status;
  1485. }
  1486. /**
  1487. * i40e_aq_update_vsi_params
  1488. * @hw: pointer to the hw struct
  1489. * @vsi_ctx: pointer to a vsi context struct
  1490. * @cmd_details: pointer to command details structure or NULL
  1491. *
  1492. * Update a VSI context.
  1493. **/
  1494. i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
  1495. struct i40e_vsi_context *vsi_ctx,
  1496. struct i40e_asq_cmd_details *cmd_details)
  1497. {
  1498. struct i40e_aq_desc desc;
  1499. struct i40e_aqc_add_get_update_vsi *cmd =
  1500. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1501. i40e_status status;
  1502. i40e_fill_default_direct_cmd_desc(&desc,
  1503. i40e_aqc_opc_update_vsi_parameters);
  1504. cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
  1505. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1506. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1507. sizeof(vsi_ctx->info), cmd_details);
  1508. return status;
  1509. }
  1510. /**
  1511. * i40e_aq_get_switch_config
  1512. * @hw: pointer to the hardware structure
  1513. * @buf: pointer to the result buffer
  1514. * @buf_size: length of input buffer
  1515. * @start_seid: seid to start for the report, 0 == beginning
  1516. * @cmd_details: pointer to command details structure or NULL
  1517. *
  1518. * Fill the buf with switch configuration returned from AdminQ command
  1519. **/
  1520. i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
  1521. struct i40e_aqc_get_switch_config_resp *buf,
  1522. u16 buf_size, u16 *start_seid,
  1523. struct i40e_asq_cmd_details *cmd_details)
  1524. {
  1525. struct i40e_aq_desc desc;
  1526. struct i40e_aqc_switch_seid *scfg =
  1527. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  1528. i40e_status status;
  1529. i40e_fill_default_direct_cmd_desc(&desc,
  1530. i40e_aqc_opc_get_switch_config);
  1531. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1532. if (buf_size > I40E_AQ_LARGE_BUF)
  1533. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1534. scfg->seid = cpu_to_le16(*start_seid);
  1535. status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
  1536. *start_seid = le16_to_cpu(scfg->seid);
  1537. return status;
  1538. }
  1539. /**
  1540. * i40e_aq_get_firmware_version
  1541. * @hw: pointer to the hw struct
  1542. * @fw_major_version: firmware major version
  1543. * @fw_minor_version: firmware minor version
  1544. * @fw_build: firmware build number
  1545. * @api_major_version: major queue version
  1546. * @api_minor_version: minor queue version
  1547. * @cmd_details: pointer to command details structure or NULL
  1548. *
  1549. * Get the firmware version from the admin queue commands
  1550. **/
  1551. i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
  1552. u16 *fw_major_version, u16 *fw_minor_version,
  1553. u32 *fw_build,
  1554. u16 *api_major_version, u16 *api_minor_version,
  1555. struct i40e_asq_cmd_details *cmd_details)
  1556. {
  1557. struct i40e_aq_desc desc;
  1558. struct i40e_aqc_get_version *resp =
  1559. (struct i40e_aqc_get_version *)&desc.params.raw;
  1560. i40e_status status;
  1561. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
  1562. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1563. if (!status) {
  1564. if (fw_major_version)
  1565. *fw_major_version = le16_to_cpu(resp->fw_major);
  1566. if (fw_minor_version)
  1567. *fw_minor_version = le16_to_cpu(resp->fw_minor);
  1568. if (fw_build)
  1569. *fw_build = le32_to_cpu(resp->fw_build);
  1570. if (api_major_version)
  1571. *api_major_version = le16_to_cpu(resp->api_major);
  1572. if (api_minor_version)
  1573. *api_minor_version = le16_to_cpu(resp->api_minor);
  1574. }
  1575. return status;
  1576. }
  1577. /**
  1578. * i40e_aq_send_driver_version
  1579. * @hw: pointer to the hw struct
  1580. * @dv: driver's major, minor version
  1581. * @cmd_details: pointer to command details structure or NULL
  1582. *
  1583. * Send the driver version to the firmware
  1584. **/
  1585. i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
  1586. struct i40e_driver_version *dv,
  1587. struct i40e_asq_cmd_details *cmd_details)
  1588. {
  1589. struct i40e_aq_desc desc;
  1590. struct i40e_aqc_driver_version *cmd =
  1591. (struct i40e_aqc_driver_version *)&desc.params.raw;
  1592. i40e_status status;
  1593. u16 len;
  1594. if (dv == NULL)
  1595. return I40E_ERR_PARAM;
  1596. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
  1597. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
  1598. cmd->driver_major_ver = dv->major_version;
  1599. cmd->driver_minor_ver = dv->minor_version;
  1600. cmd->driver_build_ver = dv->build_version;
  1601. cmd->driver_subbuild_ver = dv->subbuild_version;
  1602. len = 0;
  1603. while (len < sizeof(dv->driver_string) &&
  1604. (dv->driver_string[len] < 0x80) &&
  1605. dv->driver_string[len])
  1606. len++;
  1607. status = i40e_asq_send_command(hw, &desc, dv->driver_string,
  1608. len, cmd_details);
  1609. return status;
  1610. }
  1611. /**
  1612. * i40e_get_link_status - get status of the HW network link
  1613. * @hw: pointer to the hw struct
  1614. *
  1615. * Returns true if link is up, false if link is down.
  1616. *
  1617. * Side effect: LinkStatusEvent reporting becomes enabled
  1618. **/
  1619. bool i40e_get_link_status(struct i40e_hw *hw)
  1620. {
  1621. i40e_status status = 0;
  1622. bool link_status = false;
  1623. if (hw->phy.get_link_info) {
  1624. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  1625. if (status)
  1626. goto i40e_get_link_status_exit;
  1627. }
  1628. link_status = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  1629. i40e_get_link_status_exit:
  1630. return link_status;
  1631. }
  1632. /**
  1633. * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
  1634. * @hw: pointer to the hw struct
  1635. * @uplink_seid: the MAC or other gizmo SEID
  1636. * @downlink_seid: the VSI SEID
  1637. * @enabled_tc: bitmap of TCs to be enabled
  1638. * @default_port: true for default port VSI, false for control port
  1639. * @enable_l2_filtering: true to add L2 filter table rules to regular forwarding rules for cloud support
  1640. * @veb_seid: pointer to where to put the resulting VEB SEID
  1641. * @cmd_details: pointer to command details structure or NULL
  1642. *
  1643. * This asks the FW to add a VEB between the uplink and downlink
  1644. * elements. If the uplink SEID is 0, this will be a floating VEB.
  1645. **/
  1646. i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
  1647. u16 downlink_seid, u8 enabled_tc,
  1648. bool default_port, bool enable_l2_filtering,
  1649. u16 *veb_seid,
  1650. struct i40e_asq_cmd_details *cmd_details)
  1651. {
  1652. struct i40e_aq_desc desc;
  1653. struct i40e_aqc_add_veb *cmd =
  1654. (struct i40e_aqc_add_veb *)&desc.params.raw;
  1655. struct i40e_aqc_add_veb_completion *resp =
  1656. (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
  1657. i40e_status status;
  1658. u16 veb_flags = 0;
  1659. /* SEIDs need to either both be set or both be 0 for floating VEB */
  1660. if (!!uplink_seid != !!downlink_seid)
  1661. return I40E_ERR_PARAM;
  1662. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
  1663. cmd->uplink_seid = cpu_to_le16(uplink_seid);
  1664. cmd->downlink_seid = cpu_to_le16(downlink_seid);
  1665. cmd->enable_tcs = enabled_tc;
  1666. if (!uplink_seid)
  1667. veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
  1668. if (default_port)
  1669. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
  1670. else
  1671. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
  1672. if (enable_l2_filtering)
  1673. veb_flags |= I40E_AQC_ADD_VEB_ENABLE_L2_FILTER;
  1674. cmd->veb_flags = cpu_to_le16(veb_flags);
  1675. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1676. if (!status && veb_seid)
  1677. *veb_seid = le16_to_cpu(resp->veb_seid);
  1678. return status;
  1679. }
  1680. /**
  1681. * i40e_aq_get_veb_parameters - Retrieve VEB parameters
  1682. * @hw: pointer to the hw struct
  1683. * @veb_seid: the SEID of the VEB to query
  1684. * @switch_id: the uplink switch id
  1685. * @floating: set to true if the VEB is floating
  1686. * @statistic_index: index of the stats counter block for this VEB
  1687. * @vebs_used: number of VEB's used by function
  1688. * @vebs_free: total VEB's not reserved by any function
  1689. * @cmd_details: pointer to command details structure or NULL
  1690. *
  1691. * This retrieves the parameters for a particular VEB, specified by
  1692. * uplink_seid, and returns them to the caller.
  1693. **/
  1694. i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
  1695. u16 veb_seid, u16 *switch_id,
  1696. bool *floating, u16 *statistic_index,
  1697. u16 *vebs_used, u16 *vebs_free,
  1698. struct i40e_asq_cmd_details *cmd_details)
  1699. {
  1700. struct i40e_aq_desc desc;
  1701. struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
  1702. (struct i40e_aqc_get_veb_parameters_completion *)
  1703. &desc.params.raw;
  1704. i40e_status status;
  1705. if (veb_seid == 0)
  1706. return I40E_ERR_PARAM;
  1707. i40e_fill_default_direct_cmd_desc(&desc,
  1708. i40e_aqc_opc_get_veb_parameters);
  1709. cmd_resp->seid = cpu_to_le16(veb_seid);
  1710. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1711. if (status)
  1712. goto get_veb_exit;
  1713. if (switch_id)
  1714. *switch_id = le16_to_cpu(cmd_resp->switch_id);
  1715. if (statistic_index)
  1716. *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
  1717. if (vebs_used)
  1718. *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
  1719. if (vebs_free)
  1720. *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
  1721. if (floating) {
  1722. u16 flags = le16_to_cpu(cmd_resp->veb_flags);
  1723. if (flags & I40E_AQC_ADD_VEB_FLOATING)
  1724. *floating = true;
  1725. else
  1726. *floating = false;
  1727. }
  1728. get_veb_exit:
  1729. return status;
  1730. }
  1731. /**
  1732. * i40e_aq_add_macvlan
  1733. * @hw: pointer to the hw struct
  1734. * @seid: VSI for the mac address
  1735. * @mv_list: list of macvlans to be added
  1736. * @count: length of the list
  1737. * @cmd_details: pointer to command details structure or NULL
  1738. *
  1739. * Add MAC/VLAN addresses to the HW filtering
  1740. **/
  1741. i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
  1742. struct i40e_aqc_add_macvlan_element_data *mv_list,
  1743. u16 count, struct i40e_asq_cmd_details *cmd_details)
  1744. {
  1745. struct i40e_aq_desc desc;
  1746. struct i40e_aqc_macvlan *cmd =
  1747. (struct i40e_aqc_macvlan *)&desc.params.raw;
  1748. i40e_status status;
  1749. u16 buf_size;
  1750. if (count == 0 || !mv_list || !hw)
  1751. return I40E_ERR_PARAM;
  1752. buf_size = count * sizeof(*mv_list);
  1753. /* prep the rest of the request */
  1754. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
  1755. cmd->num_addresses = cpu_to_le16(count);
  1756. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  1757. cmd->seid[1] = 0;
  1758. cmd->seid[2] = 0;
  1759. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1760. if (buf_size > I40E_AQ_LARGE_BUF)
  1761. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1762. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  1763. cmd_details);
  1764. return status;
  1765. }
  1766. /**
  1767. * i40e_aq_remove_macvlan
  1768. * @hw: pointer to the hw struct
  1769. * @seid: VSI for the mac address
  1770. * @mv_list: list of macvlans to be removed
  1771. * @count: length of the list
  1772. * @cmd_details: pointer to command details structure or NULL
  1773. *
  1774. * Remove MAC/VLAN addresses from the HW filtering
  1775. **/
  1776. i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
  1777. struct i40e_aqc_remove_macvlan_element_data *mv_list,
  1778. u16 count, struct i40e_asq_cmd_details *cmd_details)
  1779. {
  1780. struct i40e_aq_desc desc;
  1781. struct i40e_aqc_macvlan *cmd =
  1782. (struct i40e_aqc_macvlan *)&desc.params.raw;
  1783. i40e_status status;
  1784. u16 buf_size;
  1785. if (count == 0 || !mv_list || !hw)
  1786. return I40E_ERR_PARAM;
  1787. buf_size = count * sizeof(*mv_list);
  1788. /* prep the rest of the request */
  1789. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
  1790. cmd->num_addresses = cpu_to_le16(count);
  1791. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  1792. cmd->seid[1] = 0;
  1793. cmd->seid[2] = 0;
  1794. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1795. if (buf_size > I40E_AQ_LARGE_BUF)
  1796. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1797. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  1798. cmd_details);
  1799. return status;
  1800. }
  1801. /**
  1802. * i40e_aq_send_msg_to_vf
  1803. * @hw: pointer to the hardware structure
  1804. * @vfid: VF id to send msg
  1805. * @v_opcode: opcodes for VF-PF communication
  1806. * @v_retval: return error code
  1807. * @msg: pointer to the msg buffer
  1808. * @msglen: msg length
  1809. * @cmd_details: pointer to command details
  1810. *
  1811. * send msg to vf
  1812. **/
  1813. i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
  1814. u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
  1815. struct i40e_asq_cmd_details *cmd_details)
  1816. {
  1817. struct i40e_aq_desc desc;
  1818. struct i40e_aqc_pf_vf_message *cmd =
  1819. (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
  1820. i40e_status status;
  1821. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
  1822. cmd->id = cpu_to_le32(vfid);
  1823. desc.cookie_high = cpu_to_le32(v_opcode);
  1824. desc.cookie_low = cpu_to_le32(v_retval);
  1825. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
  1826. if (msglen) {
  1827. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
  1828. I40E_AQ_FLAG_RD));
  1829. if (msglen > I40E_AQ_LARGE_BUF)
  1830. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1831. desc.datalen = cpu_to_le16(msglen);
  1832. }
  1833. status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
  1834. return status;
  1835. }
  1836. /**
  1837. * i40e_aq_debug_read_register
  1838. * @hw: pointer to the hw struct
  1839. * @reg_addr: register address
  1840. * @reg_val: register value
  1841. * @cmd_details: pointer to command details structure or NULL
  1842. *
  1843. * Read the register using the admin queue commands
  1844. **/
  1845. i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
  1846. u32 reg_addr, u64 *reg_val,
  1847. struct i40e_asq_cmd_details *cmd_details)
  1848. {
  1849. struct i40e_aq_desc desc;
  1850. struct i40e_aqc_debug_reg_read_write *cmd_resp =
  1851. (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
  1852. i40e_status status;
  1853. if (reg_val == NULL)
  1854. return I40E_ERR_PARAM;
  1855. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
  1856. cmd_resp->address = cpu_to_le32(reg_addr);
  1857. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1858. if (!status) {
  1859. *reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
  1860. (u64)le32_to_cpu(cmd_resp->value_low);
  1861. }
  1862. return status;
  1863. }
  1864. /**
  1865. * i40e_aq_debug_write_register
  1866. * @hw: pointer to the hw struct
  1867. * @reg_addr: register address
  1868. * @reg_val: register value
  1869. * @cmd_details: pointer to command details structure or NULL
  1870. *
  1871. * Write to a register using the admin queue commands
  1872. **/
  1873. i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
  1874. u32 reg_addr, u64 reg_val,
  1875. struct i40e_asq_cmd_details *cmd_details)
  1876. {
  1877. struct i40e_aq_desc desc;
  1878. struct i40e_aqc_debug_reg_read_write *cmd =
  1879. (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
  1880. i40e_status status;
  1881. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
  1882. cmd->address = cpu_to_le32(reg_addr);
  1883. cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
  1884. cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
  1885. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1886. return status;
  1887. }
  1888. /**
  1889. * i40e_aq_set_hmc_resource_profile
  1890. * @hw: pointer to the hw struct
  1891. * @profile: type of profile the HMC is to be set as
  1892. * @pe_vf_enabled_count: the number of PE enabled VFs the system has
  1893. * @cmd_details: pointer to command details structure or NULL
  1894. *
  1895. * set the HMC profile of the device.
  1896. **/
  1897. i40e_status i40e_aq_set_hmc_resource_profile(struct i40e_hw *hw,
  1898. enum i40e_aq_hmc_profile profile,
  1899. u8 pe_vf_enabled_count,
  1900. struct i40e_asq_cmd_details *cmd_details)
  1901. {
  1902. struct i40e_aq_desc desc;
  1903. struct i40e_aq_get_set_hmc_resource_profile *cmd =
  1904. (struct i40e_aq_get_set_hmc_resource_profile *)&desc.params.raw;
  1905. i40e_status status;
  1906. i40e_fill_default_direct_cmd_desc(&desc,
  1907. i40e_aqc_opc_set_hmc_resource_profile);
  1908. cmd->pm_profile = (u8)profile;
  1909. cmd->pe_vf_enabled = pe_vf_enabled_count;
  1910. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1911. return status;
  1912. }
  1913. /**
  1914. * i40e_aq_request_resource
  1915. * @hw: pointer to the hw struct
  1916. * @resource: resource id
  1917. * @access: access type
  1918. * @sdp_number: resource number
  1919. * @timeout: the maximum time in ms that the driver may hold the resource
  1920. * @cmd_details: pointer to command details structure or NULL
  1921. *
  1922. * requests common resource using the admin queue commands
  1923. **/
  1924. i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
  1925. enum i40e_aq_resources_ids resource,
  1926. enum i40e_aq_resource_access_type access,
  1927. u8 sdp_number, u64 *timeout,
  1928. struct i40e_asq_cmd_details *cmd_details)
  1929. {
  1930. struct i40e_aq_desc desc;
  1931. struct i40e_aqc_request_resource *cmd_resp =
  1932. (struct i40e_aqc_request_resource *)&desc.params.raw;
  1933. i40e_status status;
  1934. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
  1935. cmd_resp->resource_id = cpu_to_le16(resource);
  1936. cmd_resp->access_type = cpu_to_le16(access);
  1937. cmd_resp->resource_number = cpu_to_le32(sdp_number);
  1938. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1939. /* The completion specifies the maximum time in ms that the driver
  1940. * may hold the resource in the Timeout field.
  1941. * If the resource is held by someone else, the command completes with
  1942. * busy return value and the timeout field indicates the maximum time
  1943. * the current owner of the resource has to free it.
  1944. */
  1945. if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
  1946. *timeout = le32_to_cpu(cmd_resp->timeout);
  1947. return status;
  1948. }
  1949. /**
  1950. * i40e_aq_release_resource
  1951. * @hw: pointer to the hw struct
  1952. * @resource: resource id
  1953. * @sdp_number: resource number
  1954. * @cmd_details: pointer to command details structure or NULL
  1955. *
  1956. * release common resource using the admin queue commands
  1957. **/
  1958. i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
  1959. enum i40e_aq_resources_ids resource,
  1960. u8 sdp_number,
  1961. struct i40e_asq_cmd_details *cmd_details)
  1962. {
  1963. struct i40e_aq_desc desc;
  1964. struct i40e_aqc_request_resource *cmd =
  1965. (struct i40e_aqc_request_resource *)&desc.params.raw;
  1966. i40e_status status;
  1967. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
  1968. cmd->resource_id = cpu_to_le16(resource);
  1969. cmd->resource_number = cpu_to_le32(sdp_number);
  1970. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1971. return status;
  1972. }
  1973. /**
  1974. * i40e_aq_read_nvm
  1975. * @hw: pointer to the hw struct
  1976. * @module_pointer: module pointer location in words from the NVM beginning
  1977. * @offset: byte offset from the module beginning
  1978. * @length: length of the section to be read (in bytes from the offset)
  1979. * @data: command buffer (size [bytes] = length)
  1980. * @last_command: tells if this is the last command in a series
  1981. * @cmd_details: pointer to command details structure or NULL
  1982. *
  1983. * Read the NVM using the admin queue commands
  1984. **/
  1985. i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
  1986. u32 offset, u16 length, void *data,
  1987. bool last_command,
  1988. struct i40e_asq_cmd_details *cmd_details)
  1989. {
  1990. struct i40e_aq_desc desc;
  1991. struct i40e_aqc_nvm_update *cmd =
  1992. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  1993. i40e_status status;
  1994. /* In offset the highest byte must be zeroed. */
  1995. if (offset & 0xFF000000) {
  1996. status = I40E_ERR_PARAM;
  1997. goto i40e_aq_read_nvm_exit;
  1998. }
  1999. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
  2000. /* If this is the last command in a series, set the proper flag. */
  2001. if (last_command)
  2002. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2003. cmd->module_pointer = module_pointer;
  2004. cmd->offset = cpu_to_le32(offset);
  2005. cmd->length = cpu_to_le16(length);
  2006. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2007. if (length > I40E_AQ_LARGE_BUF)
  2008. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2009. status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
  2010. i40e_aq_read_nvm_exit:
  2011. return status;
  2012. }
  2013. /**
  2014. * i40e_aq_erase_nvm
  2015. * @hw: pointer to the hw struct
  2016. * @module_pointer: module pointer location in words from the NVM beginning
  2017. * @offset: offset in the module (expressed in 4 KB from module's beginning)
  2018. * @length: length of the section to be erased (expressed in 4 KB)
  2019. * @last_command: tells if this is the last command in a series
  2020. * @cmd_details: pointer to command details structure or NULL
  2021. *
  2022. * Erase the NVM sector using the admin queue commands
  2023. **/
  2024. i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
  2025. u32 offset, u16 length, bool last_command,
  2026. struct i40e_asq_cmd_details *cmd_details)
  2027. {
  2028. struct i40e_aq_desc desc;
  2029. struct i40e_aqc_nvm_update *cmd =
  2030. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  2031. i40e_status status;
  2032. /* In offset the highest byte must be zeroed. */
  2033. if (offset & 0xFF000000) {
  2034. status = I40E_ERR_PARAM;
  2035. goto i40e_aq_erase_nvm_exit;
  2036. }
  2037. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
  2038. /* If this is the last command in a series, set the proper flag. */
  2039. if (last_command)
  2040. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2041. cmd->module_pointer = module_pointer;
  2042. cmd->offset = cpu_to_le32(offset);
  2043. cmd->length = cpu_to_le16(length);
  2044. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2045. i40e_aq_erase_nvm_exit:
  2046. return status;
  2047. }
  2048. #define I40E_DEV_FUNC_CAP_SWITCH_MODE 0x01
  2049. #define I40E_DEV_FUNC_CAP_MGMT_MODE 0x02
  2050. #define I40E_DEV_FUNC_CAP_NPAR 0x03
  2051. #define I40E_DEV_FUNC_CAP_OS2BMC 0x04
  2052. #define I40E_DEV_FUNC_CAP_VALID_FUNC 0x05
  2053. #define I40E_DEV_FUNC_CAP_SRIOV_1_1 0x12
  2054. #define I40E_DEV_FUNC_CAP_VF 0x13
  2055. #define I40E_DEV_FUNC_CAP_VMDQ 0x14
  2056. #define I40E_DEV_FUNC_CAP_802_1_QBG 0x15
  2057. #define I40E_DEV_FUNC_CAP_802_1_QBH 0x16
  2058. #define I40E_DEV_FUNC_CAP_VSI 0x17
  2059. #define I40E_DEV_FUNC_CAP_DCB 0x18
  2060. #define I40E_DEV_FUNC_CAP_FCOE 0x21
  2061. #define I40E_DEV_FUNC_CAP_ISCSI 0x22
  2062. #define I40E_DEV_FUNC_CAP_RSS 0x40
  2063. #define I40E_DEV_FUNC_CAP_RX_QUEUES 0x41
  2064. #define I40E_DEV_FUNC_CAP_TX_QUEUES 0x42
  2065. #define I40E_DEV_FUNC_CAP_MSIX 0x43
  2066. #define I40E_DEV_FUNC_CAP_MSIX_VF 0x44
  2067. #define I40E_DEV_FUNC_CAP_FLOW_DIRECTOR 0x45
  2068. #define I40E_DEV_FUNC_CAP_IEEE_1588 0x46
  2069. #define I40E_DEV_FUNC_CAP_MFP_MODE_1 0xF1
  2070. #define I40E_DEV_FUNC_CAP_CEM 0xF2
  2071. #define I40E_DEV_FUNC_CAP_IWARP 0x51
  2072. #define I40E_DEV_FUNC_CAP_LED 0x61
  2073. #define I40E_DEV_FUNC_CAP_SDP 0x62
  2074. #define I40E_DEV_FUNC_CAP_MDIO 0x63
  2075. #define I40E_DEV_FUNC_CAP_WR_CSR_PROT 0x64
  2076. /**
  2077. * i40e_parse_discover_capabilities
  2078. * @hw: pointer to the hw struct
  2079. * @buff: pointer to a buffer containing device/function capability records
  2080. * @cap_count: number of capability records in the list
  2081. * @list_type_opc: type of capabilities list to parse
  2082. *
  2083. * Parse the device/function capabilities list.
  2084. **/
  2085. static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
  2086. u32 cap_count,
  2087. enum i40e_admin_queue_opc list_type_opc)
  2088. {
  2089. struct i40e_aqc_list_capabilities_element_resp *cap;
  2090. u32 valid_functions, num_functions;
  2091. u32 number, logical_id, phys_id;
  2092. struct i40e_hw_capabilities *p;
  2093. u32 i = 0;
  2094. u16 id;
  2095. cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
  2096. if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
  2097. p = &hw->dev_caps;
  2098. else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
  2099. p = &hw->func_caps;
  2100. else
  2101. return;
  2102. for (i = 0; i < cap_count; i++, cap++) {
  2103. id = le16_to_cpu(cap->id);
  2104. number = le32_to_cpu(cap->number);
  2105. logical_id = le32_to_cpu(cap->logical_id);
  2106. phys_id = le32_to_cpu(cap->phys_id);
  2107. switch (id) {
  2108. case I40E_DEV_FUNC_CAP_SWITCH_MODE:
  2109. p->switch_mode = number;
  2110. break;
  2111. case I40E_DEV_FUNC_CAP_MGMT_MODE:
  2112. p->management_mode = number;
  2113. break;
  2114. case I40E_DEV_FUNC_CAP_NPAR:
  2115. p->npar_enable = number;
  2116. break;
  2117. case I40E_DEV_FUNC_CAP_OS2BMC:
  2118. p->os2bmc = number;
  2119. break;
  2120. case I40E_DEV_FUNC_CAP_VALID_FUNC:
  2121. p->valid_functions = number;
  2122. break;
  2123. case I40E_DEV_FUNC_CAP_SRIOV_1_1:
  2124. if (number == 1)
  2125. p->sr_iov_1_1 = true;
  2126. break;
  2127. case I40E_DEV_FUNC_CAP_VF:
  2128. p->num_vfs = number;
  2129. p->vf_base_id = logical_id;
  2130. break;
  2131. case I40E_DEV_FUNC_CAP_VMDQ:
  2132. if (number == 1)
  2133. p->vmdq = true;
  2134. break;
  2135. case I40E_DEV_FUNC_CAP_802_1_QBG:
  2136. if (number == 1)
  2137. p->evb_802_1_qbg = true;
  2138. break;
  2139. case I40E_DEV_FUNC_CAP_802_1_QBH:
  2140. if (number == 1)
  2141. p->evb_802_1_qbh = true;
  2142. break;
  2143. case I40E_DEV_FUNC_CAP_VSI:
  2144. p->num_vsis = number;
  2145. break;
  2146. case I40E_DEV_FUNC_CAP_DCB:
  2147. if (number == 1) {
  2148. p->dcb = true;
  2149. p->enabled_tcmap = logical_id;
  2150. p->maxtc = phys_id;
  2151. }
  2152. break;
  2153. case I40E_DEV_FUNC_CAP_FCOE:
  2154. if (number == 1)
  2155. p->fcoe = true;
  2156. break;
  2157. case I40E_DEV_FUNC_CAP_ISCSI:
  2158. if (number == 1)
  2159. p->iscsi = true;
  2160. break;
  2161. case I40E_DEV_FUNC_CAP_RSS:
  2162. p->rss = true;
  2163. p->rss_table_size = number;
  2164. p->rss_table_entry_width = logical_id;
  2165. break;
  2166. case I40E_DEV_FUNC_CAP_RX_QUEUES:
  2167. p->num_rx_qp = number;
  2168. p->base_queue = phys_id;
  2169. break;
  2170. case I40E_DEV_FUNC_CAP_TX_QUEUES:
  2171. p->num_tx_qp = number;
  2172. p->base_queue = phys_id;
  2173. break;
  2174. case I40E_DEV_FUNC_CAP_MSIX:
  2175. p->num_msix_vectors = number;
  2176. break;
  2177. case I40E_DEV_FUNC_CAP_MSIX_VF:
  2178. p->num_msix_vectors_vf = number;
  2179. break;
  2180. case I40E_DEV_FUNC_CAP_MFP_MODE_1:
  2181. if (number == 1)
  2182. p->mfp_mode_1 = true;
  2183. break;
  2184. case I40E_DEV_FUNC_CAP_CEM:
  2185. if (number == 1)
  2186. p->mgmt_cem = true;
  2187. break;
  2188. case I40E_DEV_FUNC_CAP_IWARP:
  2189. if (number == 1)
  2190. p->iwarp = true;
  2191. break;
  2192. case I40E_DEV_FUNC_CAP_LED:
  2193. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  2194. p->led[phys_id] = true;
  2195. break;
  2196. case I40E_DEV_FUNC_CAP_SDP:
  2197. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  2198. p->sdp[phys_id] = true;
  2199. break;
  2200. case I40E_DEV_FUNC_CAP_MDIO:
  2201. if (number == 1) {
  2202. p->mdio_port_num = phys_id;
  2203. p->mdio_port_mode = logical_id;
  2204. }
  2205. break;
  2206. case I40E_DEV_FUNC_CAP_IEEE_1588:
  2207. if (number == 1)
  2208. p->ieee_1588 = true;
  2209. break;
  2210. case I40E_DEV_FUNC_CAP_FLOW_DIRECTOR:
  2211. p->fd = true;
  2212. p->fd_filters_guaranteed = number;
  2213. p->fd_filters_best_effort = logical_id;
  2214. break;
  2215. case I40E_DEV_FUNC_CAP_WR_CSR_PROT:
  2216. p->wr_csr_prot = (u64)number;
  2217. p->wr_csr_prot |= (u64)logical_id << 32;
  2218. break;
  2219. default:
  2220. break;
  2221. }
  2222. }
  2223. if (p->fcoe)
  2224. i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
  2225. /* Software override ensuring FCoE is disabled if npar or mfp
  2226. * mode because it is not supported in these modes.
  2227. */
  2228. if (p->npar_enable || p->mfp_mode_1)
  2229. p->fcoe = false;
  2230. /* count the enabled ports (aka the "not disabled" ports) */
  2231. hw->num_ports = 0;
  2232. for (i = 0; i < 4; i++) {
  2233. u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
  2234. u64 port_cfg = 0;
  2235. /* use AQ read to get the physical register offset instead
  2236. * of the port relative offset
  2237. */
  2238. i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
  2239. if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
  2240. hw->num_ports++;
  2241. }
  2242. valid_functions = p->valid_functions;
  2243. num_functions = 0;
  2244. while (valid_functions) {
  2245. if (valid_functions & 1)
  2246. num_functions++;
  2247. valid_functions >>= 1;
  2248. }
  2249. /* partition id is 1-based, and functions are evenly spread
  2250. * across the ports as partitions
  2251. */
  2252. hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
  2253. hw->num_partitions = num_functions / hw->num_ports;
  2254. /* additional HW specific goodies that might
  2255. * someday be HW version specific
  2256. */
  2257. p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
  2258. }
  2259. /**
  2260. * i40e_aq_discover_capabilities
  2261. * @hw: pointer to the hw struct
  2262. * @buff: a virtual buffer to hold the capabilities
  2263. * @buff_size: Size of the virtual buffer
  2264. * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
  2265. * @list_type_opc: capabilities type to discover - pass in the command opcode
  2266. * @cmd_details: pointer to command details structure or NULL
  2267. *
  2268. * Get the device capabilities descriptions from the firmware
  2269. **/
  2270. i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
  2271. void *buff, u16 buff_size, u16 *data_size,
  2272. enum i40e_admin_queue_opc list_type_opc,
  2273. struct i40e_asq_cmd_details *cmd_details)
  2274. {
  2275. struct i40e_aqc_list_capabilites *cmd;
  2276. struct i40e_aq_desc desc;
  2277. i40e_status status = 0;
  2278. cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
  2279. if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
  2280. list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
  2281. status = I40E_ERR_PARAM;
  2282. goto exit;
  2283. }
  2284. i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
  2285. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2286. if (buff_size > I40E_AQ_LARGE_BUF)
  2287. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2288. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2289. *data_size = le16_to_cpu(desc.datalen);
  2290. if (status)
  2291. goto exit;
  2292. i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
  2293. list_type_opc);
  2294. exit:
  2295. return status;
  2296. }
  2297. /**
  2298. * i40e_aq_update_nvm
  2299. * @hw: pointer to the hw struct
  2300. * @module_pointer: module pointer location in words from the NVM beginning
  2301. * @offset: byte offset from the module beginning
  2302. * @length: length of the section to be written (in bytes from the offset)
  2303. * @data: command buffer (size [bytes] = length)
  2304. * @last_command: tells if this is the last command in a series
  2305. * @cmd_details: pointer to command details structure or NULL
  2306. *
  2307. * Update the NVM using the admin queue commands
  2308. **/
  2309. i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
  2310. u32 offset, u16 length, void *data,
  2311. bool last_command,
  2312. struct i40e_asq_cmd_details *cmd_details)
  2313. {
  2314. struct i40e_aq_desc desc;
  2315. struct i40e_aqc_nvm_update *cmd =
  2316. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  2317. i40e_status status;
  2318. /* In offset the highest byte must be zeroed. */
  2319. if (offset & 0xFF000000) {
  2320. status = I40E_ERR_PARAM;
  2321. goto i40e_aq_update_nvm_exit;
  2322. }
  2323. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
  2324. /* If this is the last command in a series, set the proper flag. */
  2325. if (last_command)
  2326. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2327. cmd->module_pointer = module_pointer;
  2328. cmd->offset = cpu_to_le32(offset);
  2329. cmd->length = cpu_to_le16(length);
  2330. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  2331. if (length > I40E_AQ_LARGE_BUF)
  2332. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2333. status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
  2334. i40e_aq_update_nvm_exit:
  2335. return status;
  2336. }
  2337. /**
  2338. * i40e_aq_get_lldp_mib
  2339. * @hw: pointer to the hw struct
  2340. * @bridge_type: type of bridge requested
  2341. * @mib_type: Local, Remote or both Local and Remote MIBs
  2342. * @buff: pointer to a user supplied buffer to store the MIB block
  2343. * @buff_size: size of the buffer (in bytes)
  2344. * @local_len : length of the returned Local LLDP MIB
  2345. * @remote_len: length of the returned Remote LLDP MIB
  2346. * @cmd_details: pointer to command details structure or NULL
  2347. *
  2348. * Requests the complete LLDP MIB (entire packet).
  2349. **/
  2350. i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
  2351. u8 mib_type, void *buff, u16 buff_size,
  2352. u16 *local_len, u16 *remote_len,
  2353. struct i40e_asq_cmd_details *cmd_details)
  2354. {
  2355. struct i40e_aq_desc desc;
  2356. struct i40e_aqc_lldp_get_mib *cmd =
  2357. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  2358. struct i40e_aqc_lldp_get_mib *resp =
  2359. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  2360. i40e_status status;
  2361. if (buff_size == 0 || !buff)
  2362. return I40E_ERR_PARAM;
  2363. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
  2364. /* Indirect Command */
  2365. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2366. cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  2367. cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
  2368. I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  2369. desc.datalen = cpu_to_le16(buff_size);
  2370. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2371. if (buff_size > I40E_AQ_LARGE_BUF)
  2372. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2373. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2374. if (!status) {
  2375. if (local_len != NULL)
  2376. *local_len = le16_to_cpu(resp->local_len);
  2377. if (remote_len != NULL)
  2378. *remote_len = le16_to_cpu(resp->remote_len);
  2379. }
  2380. return status;
  2381. }
  2382. /**
  2383. * i40e_aq_cfg_lldp_mib_change_event
  2384. * @hw: pointer to the hw struct
  2385. * @enable_update: Enable or Disable event posting
  2386. * @cmd_details: pointer to command details structure or NULL
  2387. *
  2388. * Enable or Disable posting of an event on ARQ when LLDP MIB
  2389. * associated with the interface changes
  2390. **/
  2391. i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
  2392. bool enable_update,
  2393. struct i40e_asq_cmd_details *cmd_details)
  2394. {
  2395. struct i40e_aq_desc desc;
  2396. struct i40e_aqc_lldp_update_mib *cmd =
  2397. (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
  2398. i40e_status status;
  2399. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
  2400. if (!enable_update)
  2401. cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
  2402. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2403. return status;
  2404. }
  2405. /**
  2406. * i40e_aq_stop_lldp
  2407. * @hw: pointer to the hw struct
  2408. * @shutdown_agent: True if LLDP Agent needs to be Shutdown
  2409. * @cmd_details: pointer to command details structure or NULL
  2410. *
  2411. * Stop or Shutdown the embedded LLDP Agent
  2412. **/
  2413. i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
  2414. struct i40e_asq_cmd_details *cmd_details)
  2415. {
  2416. struct i40e_aq_desc desc;
  2417. struct i40e_aqc_lldp_stop *cmd =
  2418. (struct i40e_aqc_lldp_stop *)&desc.params.raw;
  2419. i40e_status status;
  2420. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
  2421. if (shutdown_agent)
  2422. cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
  2423. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2424. return status;
  2425. }
  2426. /**
  2427. * i40e_aq_start_lldp
  2428. * @hw: pointer to the hw struct
  2429. * @cmd_details: pointer to command details structure or NULL
  2430. *
  2431. * Start the embedded LLDP Agent on all ports.
  2432. **/
  2433. i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
  2434. struct i40e_asq_cmd_details *cmd_details)
  2435. {
  2436. struct i40e_aq_desc desc;
  2437. struct i40e_aqc_lldp_start *cmd =
  2438. (struct i40e_aqc_lldp_start *)&desc.params.raw;
  2439. i40e_status status;
  2440. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
  2441. cmd->command = I40E_AQ_LLDP_AGENT_START;
  2442. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2443. return status;
  2444. }
  2445. /**
  2446. * i40e_aq_get_cee_dcb_config
  2447. * @hw: pointer to the hw struct
  2448. * @buff: response buffer that stores CEE operational configuration
  2449. * @buff_size: size of the buffer passed
  2450. * @cmd_details: pointer to command details structure or NULL
  2451. *
  2452. * Get CEE DCBX mode operational configuration from firmware
  2453. **/
  2454. i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
  2455. void *buff, u16 buff_size,
  2456. struct i40e_asq_cmd_details *cmd_details)
  2457. {
  2458. struct i40e_aq_desc desc;
  2459. i40e_status status;
  2460. if (buff_size == 0 || !buff)
  2461. return I40E_ERR_PARAM;
  2462. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
  2463. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2464. status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
  2465. cmd_details);
  2466. return status;
  2467. }
  2468. /**
  2469. * i40e_aq_add_udp_tunnel
  2470. * @hw: pointer to the hw struct
  2471. * @udp_port: the UDP port to add
  2472. * @header_len: length of the tunneling header length in DWords
  2473. * @protocol_index: protocol index type
  2474. * @filter_index: pointer to filter index
  2475. * @cmd_details: pointer to command details structure or NULL
  2476. **/
  2477. i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
  2478. u16 udp_port, u8 protocol_index,
  2479. u8 *filter_index,
  2480. struct i40e_asq_cmd_details *cmd_details)
  2481. {
  2482. struct i40e_aq_desc desc;
  2483. struct i40e_aqc_add_udp_tunnel *cmd =
  2484. (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
  2485. struct i40e_aqc_del_udp_tunnel_completion *resp =
  2486. (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
  2487. i40e_status status;
  2488. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
  2489. cmd->udp_port = cpu_to_le16(udp_port);
  2490. cmd->protocol_type = protocol_index;
  2491. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2492. if (!status && filter_index)
  2493. *filter_index = resp->index;
  2494. return status;
  2495. }
  2496. /**
  2497. * i40e_aq_del_udp_tunnel
  2498. * @hw: pointer to the hw struct
  2499. * @index: filter index
  2500. * @cmd_details: pointer to command details structure or NULL
  2501. **/
  2502. i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
  2503. struct i40e_asq_cmd_details *cmd_details)
  2504. {
  2505. struct i40e_aq_desc desc;
  2506. struct i40e_aqc_remove_udp_tunnel *cmd =
  2507. (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
  2508. i40e_status status;
  2509. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
  2510. cmd->index = index;
  2511. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2512. return status;
  2513. }
  2514. /**
  2515. * i40e_aq_delete_element - Delete switch element
  2516. * @hw: pointer to the hw struct
  2517. * @seid: the SEID to delete from the switch
  2518. * @cmd_details: pointer to command details structure or NULL
  2519. *
  2520. * This deletes a switch element from the switch.
  2521. **/
  2522. i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
  2523. struct i40e_asq_cmd_details *cmd_details)
  2524. {
  2525. struct i40e_aq_desc desc;
  2526. struct i40e_aqc_switch_seid *cmd =
  2527. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  2528. i40e_status status;
  2529. if (seid == 0)
  2530. return I40E_ERR_PARAM;
  2531. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
  2532. cmd->seid = cpu_to_le16(seid);
  2533. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2534. return status;
  2535. }
  2536. /**
  2537. * i40e_aq_dcb_updated - DCB Updated Command
  2538. * @hw: pointer to the hw struct
  2539. * @cmd_details: pointer to command details structure or NULL
  2540. *
  2541. * EMP will return when the shared RPB settings have been
  2542. * recomputed and modified. The retval field in the descriptor
  2543. * will be set to 0 when RPB is modified.
  2544. **/
  2545. i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
  2546. struct i40e_asq_cmd_details *cmd_details)
  2547. {
  2548. struct i40e_aq_desc desc;
  2549. i40e_status status;
  2550. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
  2551. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2552. return status;
  2553. }
  2554. /**
  2555. * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
  2556. * @hw: pointer to the hw struct
  2557. * @seid: seid for the physical port/switching component/vsi
  2558. * @buff: Indirect buffer to hold data parameters and response
  2559. * @buff_size: Indirect buffer size
  2560. * @opcode: Tx scheduler AQ command opcode
  2561. * @cmd_details: pointer to command details structure or NULL
  2562. *
  2563. * Generic command handler for Tx scheduler AQ commands
  2564. **/
  2565. static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
  2566. void *buff, u16 buff_size,
  2567. enum i40e_admin_queue_opc opcode,
  2568. struct i40e_asq_cmd_details *cmd_details)
  2569. {
  2570. struct i40e_aq_desc desc;
  2571. struct i40e_aqc_tx_sched_ind *cmd =
  2572. (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
  2573. i40e_status status;
  2574. bool cmd_param_flag = false;
  2575. switch (opcode) {
  2576. case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
  2577. case i40e_aqc_opc_configure_vsi_tc_bw:
  2578. case i40e_aqc_opc_enable_switching_comp_ets:
  2579. case i40e_aqc_opc_modify_switching_comp_ets:
  2580. case i40e_aqc_opc_disable_switching_comp_ets:
  2581. case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
  2582. case i40e_aqc_opc_configure_switching_comp_bw_config:
  2583. cmd_param_flag = true;
  2584. break;
  2585. case i40e_aqc_opc_query_vsi_bw_config:
  2586. case i40e_aqc_opc_query_vsi_ets_sla_config:
  2587. case i40e_aqc_opc_query_switching_comp_ets_config:
  2588. case i40e_aqc_opc_query_port_ets_config:
  2589. case i40e_aqc_opc_query_switching_comp_bw_config:
  2590. cmd_param_flag = false;
  2591. break;
  2592. default:
  2593. return I40E_ERR_PARAM;
  2594. }
  2595. i40e_fill_default_direct_cmd_desc(&desc, opcode);
  2596. /* Indirect command */
  2597. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2598. if (cmd_param_flag)
  2599. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  2600. if (buff_size > I40E_AQ_LARGE_BUF)
  2601. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2602. desc.datalen = cpu_to_le16(buff_size);
  2603. cmd->vsi_seid = cpu_to_le16(seid);
  2604. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2605. return status;
  2606. }
  2607. /**
  2608. * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
  2609. * @hw: pointer to the hw struct
  2610. * @seid: VSI seid
  2611. * @credit: BW limit credits (0 = disabled)
  2612. * @max_credit: Max BW limit credits
  2613. * @cmd_details: pointer to command details structure or NULL
  2614. **/
  2615. i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
  2616. u16 seid, u16 credit, u8 max_credit,
  2617. struct i40e_asq_cmd_details *cmd_details)
  2618. {
  2619. struct i40e_aq_desc desc;
  2620. struct i40e_aqc_configure_vsi_bw_limit *cmd =
  2621. (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
  2622. i40e_status status;
  2623. i40e_fill_default_direct_cmd_desc(&desc,
  2624. i40e_aqc_opc_configure_vsi_bw_limit);
  2625. cmd->vsi_seid = cpu_to_le16(seid);
  2626. cmd->credit = cpu_to_le16(credit);
  2627. cmd->max_credit = max_credit;
  2628. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2629. return status;
  2630. }
  2631. /**
  2632. * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
  2633. * @hw: pointer to the hw struct
  2634. * @seid: VSI seid
  2635. * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
  2636. * @cmd_details: pointer to command details structure or NULL
  2637. **/
  2638. i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
  2639. u16 seid,
  2640. struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
  2641. struct i40e_asq_cmd_details *cmd_details)
  2642. {
  2643. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2644. i40e_aqc_opc_configure_vsi_tc_bw,
  2645. cmd_details);
  2646. }
  2647. /**
  2648. * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
  2649. * @hw: pointer to the hw struct
  2650. * @seid: seid of the switching component connected to Physical Port
  2651. * @ets_data: Buffer holding ETS parameters
  2652. * @cmd_details: pointer to command details structure or NULL
  2653. **/
  2654. i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
  2655. u16 seid,
  2656. struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
  2657. enum i40e_admin_queue_opc opcode,
  2658. struct i40e_asq_cmd_details *cmd_details)
  2659. {
  2660. return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
  2661. sizeof(*ets_data), opcode, cmd_details);
  2662. }
  2663. /**
  2664. * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
  2665. * @hw: pointer to the hw struct
  2666. * @seid: seid of the switching component
  2667. * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
  2668. * @cmd_details: pointer to command details structure or NULL
  2669. **/
  2670. i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
  2671. u16 seid,
  2672. struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
  2673. struct i40e_asq_cmd_details *cmd_details)
  2674. {
  2675. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2676. i40e_aqc_opc_configure_switching_comp_bw_config,
  2677. cmd_details);
  2678. }
  2679. /**
  2680. * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
  2681. * @hw: pointer to the hw struct
  2682. * @seid: seid of the VSI
  2683. * @bw_data: Buffer to hold VSI BW configuration
  2684. * @cmd_details: pointer to command details structure or NULL
  2685. **/
  2686. i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
  2687. u16 seid,
  2688. struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
  2689. struct i40e_asq_cmd_details *cmd_details)
  2690. {
  2691. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2692. i40e_aqc_opc_query_vsi_bw_config,
  2693. cmd_details);
  2694. }
  2695. /**
  2696. * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
  2697. * @hw: pointer to the hw struct
  2698. * @seid: seid of the VSI
  2699. * @bw_data: Buffer to hold VSI BW configuration per TC
  2700. * @cmd_details: pointer to command details structure or NULL
  2701. **/
  2702. i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
  2703. u16 seid,
  2704. struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
  2705. struct i40e_asq_cmd_details *cmd_details)
  2706. {
  2707. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2708. i40e_aqc_opc_query_vsi_ets_sla_config,
  2709. cmd_details);
  2710. }
  2711. /**
  2712. * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
  2713. * @hw: pointer to the hw struct
  2714. * @seid: seid of the switching component
  2715. * @bw_data: Buffer to hold switching component's per TC BW config
  2716. * @cmd_details: pointer to command details structure or NULL
  2717. **/
  2718. i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
  2719. u16 seid,
  2720. struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
  2721. struct i40e_asq_cmd_details *cmd_details)
  2722. {
  2723. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2724. i40e_aqc_opc_query_switching_comp_ets_config,
  2725. cmd_details);
  2726. }
  2727. /**
  2728. * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
  2729. * @hw: pointer to the hw struct
  2730. * @seid: seid of the VSI or switching component connected to Physical Port
  2731. * @bw_data: Buffer to hold current ETS configuration for the Physical Port
  2732. * @cmd_details: pointer to command details structure or NULL
  2733. **/
  2734. i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
  2735. u16 seid,
  2736. struct i40e_aqc_query_port_ets_config_resp *bw_data,
  2737. struct i40e_asq_cmd_details *cmd_details)
  2738. {
  2739. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2740. i40e_aqc_opc_query_port_ets_config,
  2741. cmd_details);
  2742. }
  2743. /**
  2744. * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
  2745. * @hw: pointer to the hw struct
  2746. * @seid: seid of the switching component
  2747. * @bw_data: Buffer to hold switching component's BW configuration
  2748. * @cmd_details: pointer to command details structure or NULL
  2749. **/
  2750. i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
  2751. u16 seid,
  2752. struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
  2753. struct i40e_asq_cmd_details *cmd_details)
  2754. {
  2755. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2756. i40e_aqc_opc_query_switching_comp_bw_config,
  2757. cmd_details);
  2758. }
  2759. /**
  2760. * i40e_validate_filter_settings
  2761. * @hw: pointer to the hardware structure
  2762. * @settings: Filter control settings
  2763. *
  2764. * Check and validate the filter control settings passed.
  2765. * The function checks for the valid filter/context sizes being
  2766. * passed for FCoE and PE.
  2767. *
  2768. * Returns 0 if the values passed are valid and within
  2769. * range else returns an error.
  2770. **/
  2771. static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
  2772. struct i40e_filter_control_settings *settings)
  2773. {
  2774. u32 fcoe_cntx_size, fcoe_filt_size;
  2775. u32 pe_cntx_size, pe_filt_size;
  2776. u32 fcoe_fmax;
  2777. u32 val;
  2778. /* Validate FCoE settings passed */
  2779. switch (settings->fcoe_filt_num) {
  2780. case I40E_HASH_FILTER_SIZE_1K:
  2781. case I40E_HASH_FILTER_SIZE_2K:
  2782. case I40E_HASH_FILTER_SIZE_4K:
  2783. case I40E_HASH_FILTER_SIZE_8K:
  2784. case I40E_HASH_FILTER_SIZE_16K:
  2785. case I40E_HASH_FILTER_SIZE_32K:
  2786. fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  2787. fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
  2788. break;
  2789. default:
  2790. return I40E_ERR_PARAM;
  2791. }
  2792. switch (settings->fcoe_cntx_num) {
  2793. case I40E_DMA_CNTX_SIZE_512:
  2794. case I40E_DMA_CNTX_SIZE_1K:
  2795. case I40E_DMA_CNTX_SIZE_2K:
  2796. case I40E_DMA_CNTX_SIZE_4K:
  2797. fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  2798. fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
  2799. break;
  2800. default:
  2801. return I40E_ERR_PARAM;
  2802. }
  2803. /* Validate PE settings passed */
  2804. switch (settings->pe_filt_num) {
  2805. case I40E_HASH_FILTER_SIZE_1K:
  2806. case I40E_HASH_FILTER_SIZE_2K:
  2807. case I40E_HASH_FILTER_SIZE_4K:
  2808. case I40E_HASH_FILTER_SIZE_8K:
  2809. case I40E_HASH_FILTER_SIZE_16K:
  2810. case I40E_HASH_FILTER_SIZE_32K:
  2811. case I40E_HASH_FILTER_SIZE_64K:
  2812. case I40E_HASH_FILTER_SIZE_128K:
  2813. case I40E_HASH_FILTER_SIZE_256K:
  2814. case I40E_HASH_FILTER_SIZE_512K:
  2815. case I40E_HASH_FILTER_SIZE_1M:
  2816. pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  2817. pe_filt_size <<= (u32)settings->pe_filt_num;
  2818. break;
  2819. default:
  2820. return I40E_ERR_PARAM;
  2821. }
  2822. switch (settings->pe_cntx_num) {
  2823. case I40E_DMA_CNTX_SIZE_512:
  2824. case I40E_DMA_CNTX_SIZE_1K:
  2825. case I40E_DMA_CNTX_SIZE_2K:
  2826. case I40E_DMA_CNTX_SIZE_4K:
  2827. case I40E_DMA_CNTX_SIZE_8K:
  2828. case I40E_DMA_CNTX_SIZE_16K:
  2829. case I40E_DMA_CNTX_SIZE_32K:
  2830. case I40E_DMA_CNTX_SIZE_64K:
  2831. case I40E_DMA_CNTX_SIZE_128K:
  2832. case I40E_DMA_CNTX_SIZE_256K:
  2833. pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  2834. pe_cntx_size <<= (u32)settings->pe_cntx_num;
  2835. break;
  2836. default:
  2837. return I40E_ERR_PARAM;
  2838. }
  2839. /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
  2840. val = rd32(hw, I40E_GLHMC_FCOEFMAX);
  2841. fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
  2842. >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
  2843. if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
  2844. return I40E_ERR_INVALID_SIZE;
  2845. return 0;
  2846. }
  2847. /**
  2848. * i40e_set_filter_control
  2849. * @hw: pointer to the hardware structure
  2850. * @settings: Filter control settings
  2851. *
  2852. * Set the Queue Filters for PE/FCoE and enable filters required
  2853. * for a single PF. It is expected that these settings are programmed
  2854. * at the driver initialization time.
  2855. **/
  2856. i40e_status i40e_set_filter_control(struct i40e_hw *hw,
  2857. struct i40e_filter_control_settings *settings)
  2858. {
  2859. i40e_status ret = 0;
  2860. u32 hash_lut_size = 0;
  2861. u32 val;
  2862. if (!settings)
  2863. return I40E_ERR_PARAM;
  2864. /* Validate the input settings */
  2865. ret = i40e_validate_filter_settings(hw, settings);
  2866. if (ret)
  2867. return ret;
  2868. /* Read the PF Queue Filter control register */
  2869. val = rd32(hw, I40E_PFQF_CTL_0);
  2870. /* Program required PE hash buckets for the PF */
  2871. val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
  2872. val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
  2873. I40E_PFQF_CTL_0_PEHSIZE_MASK;
  2874. /* Program required PE contexts for the PF */
  2875. val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
  2876. val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
  2877. I40E_PFQF_CTL_0_PEDSIZE_MASK;
  2878. /* Program required FCoE hash buckets for the PF */
  2879. val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  2880. val |= ((u32)settings->fcoe_filt_num <<
  2881. I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
  2882. I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  2883. /* Program required FCoE DDP contexts for the PF */
  2884. val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  2885. val |= ((u32)settings->fcoe_cntx_num <<
  2886. I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
  2887. I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  2888. /* Program Hash LUT size for the PF */
  2889. val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  2890. if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
  2891. hash_lut_size = 1;
  2892. val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
  2893. I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  2894. /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
  2895. if (settings->enable_fdir)
  2896. val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
  2897. if (settings->enable_ethtype)
  2898. val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
  2899. if (settings->enable_macvlan)
  2900. val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
  2901. wr32(hw, I40E_PFQF_CTL_0, val);
  2902. return 0;
  2903. }
  2904. /**
  2905. * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
  2906. * @hw: pointer to the hw struct
  2907. * @mac_addr: MAC address to use in the filter
  2908. * @ethtype: Ethertype to use in the filter
  2909. * @flags: Flags that needs to be applied to the filter
  2910. * @vsi_seid: seid of the control VSI
  2911. * @queue: VSI queue number to send the packet to
  2912. * @is_add: Add control packet filter if True else remove
  2913. * @stats: Structure to hold information on control filter counts
  2914. * @cmd_details: pointer to command details structure or NULL
  2915. *
  2916. * This command will Add or Remove control packet filter for a control VSI.
  2917. * In return it will update the total number of perfect filter count in
  2918. * the stats member.
  2919. **/
  2920. i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
  2921. u8 *mac_addr, u16 ethtype, u16 flags,
  2922. u16 vsi_seid, u16 queue, bool is_add,
  2923. struct i40e_control_filter_stats *stats,
  2924. struct i40e_asq_cmd_details *cmd_details)
  2925. {
  2926. struct i40e_aq_desc desc;
  2927. struct i40e_aqc_add_remove_control_packet_filter *cmd =
  2928. (struct i40e_aqc_add_remove_control_packet_filter *)
  2929. &desc.params.raw;
  2930. struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
  2931. (struct i40e_aqc_add_remove_control_packet_filter_completion *)
  2932. &desc.params.raw;
  2933. i40e_status status;
  2934. if (vsi_seid == 0)
  2935. return I40E_ERR_PARAM;
  2936. if (is_add) {
  2937. i40e_fill_default_direct_cmd_desc(&desc,
  2938. i40e_aqc_opc_add_control_packet_filter);
  2939. cmd->queue = cpu_to_le16(queue);
  2940. } else {
  2941. i40e_fill_default_direct_cmd_desc(&desc,
  2942. i40e_aqc_opc_remove_control_packet_filter);
  2943. }
  2944. if (mac_addr)
  2945. memcpy(cmd->mac, mac_addr, ETH_ALEN);
  2946. cmd->etype = cpu_to_le16(ethtype);
  2947. cmd->flags = cpu_to_le16(flags);
  2948. cmd->seid = cpu_to_le16(vsi_seid);
  2949. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2950. if (!status && stats) {
  2951. stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
  2952. stats->etype_used = le16_to_cpu(resp->etype_used);
  2953. stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
  2954. stats->etype_free = le16_to_cpu(resp->etype_free);
  2955. }
  2956. return status;
  2957. }
  2958. /**
  2959. * i40e_aq_alternate_read
  2960. * @hw: pointer to the hardware structure
  2961. * @reg_addr0: address of first dword to be read
  2962. * @reg_val0: pointer for data read from 'reg_addr0'
  2963. * @reg_addr1: address of second dword to be read
  2964. * @reg_val1: pointer for data read from 'reg_addr1'
  2965. *
  2966. * Read one or two dwords from alternate structure. Fields are indicated
  2967. * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
  2968. * is not passed then only register at 'reg_addr0' is read.
  2969. *
  2970. **/
  2971. static i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
  2972. u32 reg_addr0, u32 *reg_val0,
  2973. u32 reg_addr1, u32 *reg_val1)
  2974. {
  2975. struct i40e_aq_desc desc;
  2976. struct i40e_aqc_alternate_write *cmd_resp =
  2977. (struct i40e_aqc_alternate_write *)&desc.params.raw;
  2978. i40e_status status;
  2979. if (!reg_val0)
  2980. return I40E_ERR_PARAM;
  2981. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
  2982. cmd_resp->address0 = cpu_to_le32(reg_addr0);
  2983. cmd_resp->address1 = cpu_to_le32(reg_addr1);
  2984. status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
  2985. if (!status) {
  2986. *reg_val0 = le32_to_cpu(cmd_resp->data0);
  2987. if (reg_val1)
  2988. *reg_val1 = le32_to_cpu(cmd_resp->data1);
  2989. }
  2990. return status;
  2991. }
  2992. /**
  2993. * i40e_aq_resume_port_tx
  2994. * @hw: pointer to the hardware structure
  2995. * @cmd_details: pointer to command details structure or NULL
  2996. *
  2997. * Resume port's Tx traffic
  2998. **/
  2999. i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
  3000. struct i40e_asq_cmd_details *cmd_details)
  3001. {
  3002. struct i40e_aq_desc desc;
  3003. i40e_status status;
  3004. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
  3005. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3006. return status;
  3007. }
  3008. /**
  3009. * i40e_set_pci_config_data - store PCI bus info
  3010. * @hw: pointer to hardware structure
  3011. * @link_status: the link status word from PCI config space
  3012. *
  3013. * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
  3014. **/
  3015. void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
  3016. {
  3017. hw->bus.type = i40e_bus_type_pci_express;
  3018. switch (link_status & PCI_EXP_LNKSTA_NLW) {
  3019. case PCI_EXP_LNKSTA_NLW_X1:
  3020. hw->bus.width = i40e_bus_width_pcie_x1;
  3021. break;
  3022. case PCI_EXP_LNKSTA_NLW_X2:
  3023. hw->bus.width = i40e_bus_width_pcie_x2;
  3024. break;
  3025. case PCI_EXP_LNKSTA_NLW_X4:
  3026. hw->bus.width = i40e_bus_width_pcie_x4;
  3027. break;
  3028. case PCI_EXP_LNKSTA_NLW_X8:
  3029. hw->bus.width = i40e_bus_width_pcie_x8;
  3030. break;
  3031. default:
  3032. hw->bus.width = i40e_bus_width_unknown;
  3033. break;
  3034. }
  3035. switch (link_status & PCI_EXP_LNKSTA_CLS) {
  3036. case PCI_EXP_LNKSTA_CLS_2_5GB:
  3037. hw->bus.speed = i40e_bus_speed_2500;
  3038. break;
  3039. case PCI_EXP_LNKSTA_CLS_5_0GB:
  3040. hw->bus.speed = i40e_bus_speed_5000;
  3041. break;
  3042. case PCI_EXP_LNKSTA_CLS_8_0GB:
  3043. hw->bus.speed = i40e_bus_speed_8000;
  3044. break;
  3045. default:
  3046. hw->bus.speed = i40e_bus_speed_unknown;
  3047. break;
  3048. }
  3049. }
  3050. /**
  3051. * i40e_aq_debug_dump
  3052. * @hw: pointer to the hardware structure
  3053. * @cluster_id: specific cluster to dump
  3054. * @table_id: table id within cluster
  3055. * @start_index: index of line in the block to read
  3056. * @buff_size: dump buffer size
  3057. * @buff: dump buffer
  3058. * @ret_buff_size: actual buffer size returned
  3059. * @ret_next_table: next block to read
  3060. * @ret_next_index: next index to read
  3061. *
  3062. * Dump internal FW/HW data for debug purposes.
  3063. *
  3064. **/
  3065. i40e_status i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
  3066. u8 table_id, u32 start_index, u16 buff_size,
  3067. void *buff, u16 *ret_buff_size,
  3068. u8 *ret_next_table, u32 *ret_next_index,
  3069. struct i40e_asq_cmd_details *cmd_details)
  3070. {
  3071. struct i40e_aq_desc desc;
  3072. struct i40e_aqc_debug_dump_internals *cmd =
  3073. (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
  3074. struct i40e_aqc_debug_dump_internals *resp =
  3075. (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
  3076. i40e_status status;
  3077. if (buff_size == 0 || !buff)
  3078. return I40E_ERR_PARAM;
  3079. i40e_fill_default_direct_cmd_desc(&desc,
  3080. i40e_aqc_opc_debug_dump_internals);
  3081. /* Indirect Command */
  3082. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3083. if (buff_size > I40E_AQ_LARGE_BUF)
  3084. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  3085. cmd->cluster_id = cluster_id;
  3086. cmd->table_id = table_id;
  3087. cmd->idx = cpu_to_le32(start_index);
  3088. desc.datalen = cpu_to_le16(buff_size);
  3089. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  3090. if (!status) {
  3091. if (ret_buff_size)
  3092. *ret_buff_size = le16_to_cpu(desc.datalen);
  3093. if (ret_next_table)
  3094. *ret_next_table = resp->table_id;
  3095. if (ret_next_index)
  3096. *ret_next_index = le32_to_cpu(resp->idx);
  3097. }
  3098. return status;
  3099. }
  3100. /**
  3101. * i40e_read_bw_from_alt_ram
  3102. * @hw: pointer to the hardware structure
  3103. * @max_bw: pointer for max_bw read
  3104. * @min_bw: pointer for min_bw read
  3105. * @min_valid: pointer for bool that is true if min_bw is a valid value
  3106. * @max_valid: pointer for bool that is true if max_bw is a valid value
  3107. *
  3108. * Read bw from the alternate ram for the given pf
  3109. **/
  3110. i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
  3111. u32 *max_bw, u32 *min_bw,
  3112. bool *min_valid, bool *max_valid)
  3113. {
  3114. i40e_status status;
  3115. u32 max_bw_addr, min_bw_addr;
  3116. /* Calculate the address of the min/max bw registers */
  3117. max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
  3118. I40E_ALT_STRUCT_MAX_BW_OFFSET +
  3119. (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
  3120. min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
  3121. I40E_ALT_STRUCT_MIN_BW_OFFSET +
  3122. (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
  3123. /* Read the bandwidths from alt ram */
  3124. status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
  3125. min_bw_addr, min_bw);
  3126. if (*min_bw & I40E_ALT_BW_VALID_MASK)
  3127. *min_valid = true;
  3128. else
  3129. *min_valid = false;
  3130. if (*max_bw & I40E_ALT_BW_VALID_MASK)
  3131. *max_valid = true;
  3132. else
  3133. *max_valid = false;
  3134. return status;
  3135. }
  3136. /**
  3137. * i40e_aq_configure_partition_bw
  3138. * @hw: pointer to the hardware structure
  3139. * @bw_data: Buffer holding valid pfs and bw limits
  3140. * @cmd_details: pointer to command details
  3141. *
  3142. * Configure partitions guaranteed/max bw
  3143. **/
  3144. i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
  3145. struct i40e_aqc_configure_partition_bw_data *bw_data,
  3146. struct i40e_asq_cmd_details *cmd_details)
  3147. {
  3148. i40e_status status;
  3149. struct i40e_aq_desc desc;
  3150. u16 bwd_size = sizeof(*bw_data);
  3151. i40e_fill_default_direct_cmd_desc(&desc,
  3152. i40e_aqc_opc_configure_partition_bw);
  3153. /* Indirect command */
  3154. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3155. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  3156. if (bwd_size > I40E_AQ_LARGE_BUF)
  3157. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  3158. desc.datalen = cpu_to_le16(bwd_size);
  3159. status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
  3160. cmd_details);
  3161. return status;
  3162. }