t4_hw.c 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2010 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/init.h>
  35. #include <linux/delay.h>
  36. #include "cxgb4.h"
  37. #include "t4_regs.h"
  38. #include "t4fw_api.h"
  39. /**
  40. * t4_wait_op_done_val - wait until an operation is completed
  41. * @adapter: the adapter performing the operation
  42. * @reg: the register to check for completion
  43. * @mask: a single-bit field within @reg that indicates completion
  44. * @polarity: the value of the field when the operation is completed
  45. * @attempts: number of check iterations
  46. * @delay: delay in usecs between iterations
  47. * @valp: where to store the value of the register at completion time
  48. *
  49. * Wait until an operation is completed by checking a bit in a register
  50. * up to @attempts times. If @valp is not NULL the value of the register
  51. * at the time it indicated completion is stored there. Returns 0 if the
  52. * operation completes and -EAGAIN otherwise.
  53. */
  54. static int t4_wait_op_done_val(struct adapter *adapter, int reg, u32 mask,
  55. int polarity, int attempts, int delay, u32 *valp)
  56. {
  57. while (1) {
  58. u32 val = t4_read_reg(adapter, reg);
  59. if (!!(val & mask) == polarity) {
  60. if (valp)
  61. *valp = val;
  62. return 0;
  63. }
  64. if (--attempts == 0)
  65. return -EAGAIN;
  66. if (delay)
  67. udelay(delay);
  68. }
  69. }
  70. static inline int t4_wait_op_done(struct adapter *adapter, int reg, u32 mask,
  71. int polarity, int attempts, int delay)
  72. {
  73. return t4_wait_op_done_val(adapter, reg, mask, polarity, attempts,
  74. delay, NULL);
  75. }
  76. /**
  77. * t4_set_reg_field - set a register field to a value
  78. * @adapter: the adapter to program
  79. * @addr: the register address
  80. * @mask: specifies the portion of the register to modify
  81. * @val: the new value for the register field
  82. *
  83. * Sets a register field specified by the supplied mask to the
  84. * given value.
  85. */
  86. void t4_set_reg_field(struct adapter *adapter, unsigned int addr, u32 mask,
  87. u32 val)
  88. {
  89. u32 v = t4_read_reg(adapter, addr) & ~mask;
  90. t4_write_reg(adapter, addr, v | val);
  91. (void) t4_read_reg(adapter, addr); /* flush */
  92. }
  93. /**
  94. * t4_read_indirect - read indirectly addressed registers
  95. * @adap: the adapter
  96. * @addr_reg: register holding the indirect address
  97. * @data_reg: register holding the value of the indirect register
  98. * @vals: where the read register values are stored
  99. * @nregs: how many indirect registers to read
  100. * @start_idx: index of first indirect register to read
  101. *
  102. * Reads registers that are accessed indirectly through an address/data
  103. * register pair.
  104. */
  105. static void t4_read_indirect(struct adapter *adap, unsigned int addr_reg,
  106. unsigned int data_reg, u32 *vals,
  107. unsigned int nregs, unsigned int start_idx)
  108. {
  109. while (nregs--) {
  110. t4_write_reg(adap, addr_reg, start_idx);
  111. *vals++ = t4_read_reg(adap, data_reg);
  112. start_idx++;
  113. }
  114. }
  115. #if 0
  116. /**
  117. * t4_write_indirect - write indirectly addressed registers
  118. * @adap: the adapter
  119. * @addr_reg: register holding the indirect addresses
  120. * @data_reg: register holding the value for the indirect registers
  121. * @vals: values to write
  122. * @nregs: how many indirect registers to write
  123. * @start_idx: address of first indirect register to write
  124. *
  125. * Writes a sequential block of registers that are accessed indirectly
  126. * through an address/data register pair.
  127. */
  128. static void t4_write_indirect(struct adapter *adap, unsigned int addr_reg,
  129. unsigned int data_reg, const u32 *vals,
  130. unsigned int nregs, unsigned int start_idx)
  131. {
  132. while (nregs--) {
  133. t4_write_reg(adap, addr_reg, start_idx++);
  134. t4_write_reg(adap, data_reg, *vals++);
  135. }
  136. }
  137. #endif
  138. /*
  139. * Get the reply to a mailbox command and store it in @rpl in big-endian order.
  140. */
  141. static void get_mbox_rpl(struct adapter *adap, __be64 *rpl, int nflit,
  142. u32 mbox_addr)
  143. {
  144. for ( ; nflit; nflit--, mbox_addr += 8)
  145. *rpl++ = cpu_to_be64(t4_read_reg64(adap, mbox_addr));
  146. }
  147. /*
  148. * Handle a FW assertion reported in a mailbox.
  149. */
  150. static void fw_asrt(struct adapter *adap, u32 mbox_addr)
  151. {
  152. struct fw_debug_cmd asrt;
  153. get_mbox_rpl(adap, (__be64 *)&asrt, sizeof(asrt) / 8, mbox_addr);
  154. dev_alert(adap->pdev_dev,
  155. "FW assertion at %.16s:%u, val0 %#x, val1 %#x\n",
  156. asrt.u.assert.filename_0_7, ntohl(asrt.u.assert.line),
  157. ntohl(asrt.u.assert.x), ntohl(asrt.u.assert.y));
  158. }
  159. static void dump_mbox(struct adapter *adap, int mbox, u32 data_reg)
  160. {
  161. dev_err(adap->pdev_dev,
  162. "mbox %d: %llx %llx %llx %llx %llx %llx %llx %llx\n", mbox,
  163. (unsigned long long)t4_read_reg64(adap, data_reg),
  164. (unsigned long long)t4_read_reg64(adap, data_reg + 8),
  165. (unsigned long long)t4_read_reg64(adap, data_reg + 16),
  166. (unsigned long long)t4_read_reg64(adap, data_reg + 24),
  167. (unsigned long long)t4_read_reg64(adap, data_reg + 32),
  168. (unsigned long long)t4_read_reg64(adap, data_reg + 40),
  169. (unsigned long long)t4_read_reg64(adap, data_reg + 48),
  170. (unsigned long long)t4_read_reg64(adap, data_reg + 56));
  171. }
  172. /**
  173. * t4_wr_mbox_meat - send a command to FW through the given mailbox
  174. * @adap: the adapter
  175. * @mbox: index of the mailbox to use
  176. * @cmd: the command to write
  177. * @size: command length in bytes
  178. * @rpl: where to optionally store the reply
  179. * @sleep_ok: if true we may sleep while awaiting command completion
  180. *
  181. * Sends the given command to FW through the selected mailbox and waits
  182. * for the FW to execute the command. If @rpl is not %NULL it is used to
  183. * store the FW's reply to the command. The command and its optional
  184. * reply are of the same length. FW can take up to %FW_CMD_MAX_TIMEOUT ms
  185. * to respond. @sleep_ok determines whether we may sleep while awaiting
  186. * the response. If sleeping is allowed we use progressive backoff
  187. * otherwise we spin.
  188. *
  189. * The return value is 0 on success or a negative errno on failure. A
  190. * failure can happen either because we are not able to execute the
  191. * command or FW executes it but signals an error. In the latter case
  192. * the return value is the error code indicated by FW (negated).
  193. */
  194. int t4_wr_mbox_meat(struct adapter *adap, int mbox, const void *cmd, int size,
  195. void *rpl, bool sleep_ok)
  196. {
  197. static int delay[] = {
  198. 1, 1, 3, 5, 10, 10, 20, 50, 100, 200
  199. };
  200. u32 v;
  201. u64 res;
  202. int i, ms, delay_idx;
  203. const __be64 *p = cmd;
  204. u32 data_reg = PF_REG(mbox, CIM_PF_MAILBOX_DATA);
  205. u32 ctl_reg = PF_REG(mbox, CIM_PF_MAILBOX_CTRL);
  206. if ((size & 15) || size > MBOX_LEN)
  207. return -EINVAL;
  208. v = MBOWNER_GET(t4_read_reg(adap, ctl_reg));
  209. for (i = 0; v == MBOX_OWNER_NONE && i < 3; i++)
  210. v = MBOWNER_GET(t4_read_reg(adap, ctl_reg));
  211. if (v != MBOX_OWNER_DRV)
  212. return v ? -EBUSY : -ETIMEDOUT;
  213. for (i = 0; i < size; i += 8)
  214. t4_write_reg64(adap, data_reg + i, be64_to_cpu(*p++));
  215. t4_write_reg(adap, ctl_reg, MBMSGVALID | MBOWNER(MBOX_OWNER_FW));
  216. t4_read_reg(adap, ctl_reg); /* flush write */
  217. delay_idx = 0;
  218. ms = delay[0];
  219. for (i = 0; i < FW_CMD_MAX_TIMEOUT; i += ms) {
  220. if (sleep_ok) {
  221. ms = delay[delay_idx]; /* last element may repeat */
  222. if (delay_idx < ARRAY_SIZE(delay) - 1)
  223. delay_idx++;
  224. msleep(ms);
  225. } else
  226. mdelay(ms);
  227. v = t4_read_reg(adap, ctl_reg);
  228. if (MBOWNER_GET(v) == MBOX_OWNER_DRV) {
  229. if (!(v & MBMSGVALID)) {
  230. t4_write_reg(adap, ctl_reg, 0);
  231. continue;
  232. }
  233. res = t4_read_reg64(adap, data_reg);
  234. if (FW_CMD_OP_GET(res >> 32) == FW_DEBUG_CMD) {
  235. fw_asrt(adap, data_reg);
  236. res = FW_CMD_RETVAL(EIO);
  237. } else if (rpl)
  238. get_mbox_rpl(adap, rpl, size / 8, data_reg);
  239. if (FW_CMD_RETVAL_GET((int)res))
  240. dump_mbox(adap, mbox, data_reg);
  241. t4_write_reg(adap, ctl_reg, 0);
  242. return -FW_CMD_RETVAL_GET((int)res);
  243. }
  244. }
  245. dump_mbox(adap, mbox, data_reg);
  246. dev_err(adap->pdev_dev, "command %#x in mailbox %d timed out\n",
  247. *(const u8 *)cmd, mbox);
  248. return -ETIMEDOUT;
  249. }
  250. /**
  251. * t4_mc_read - read from MC through backdoor accesses
  252. * @adap: the adapter
  253. * @addr: address of first byte requested
  254. * @data: 64 bytes of data containing the requested address
  255. * @ecc: where to store the corresponding 64-bit ECC word
  256. *
  257. * Read 64 bytes of data from MC starting at a 64-byte-aligned address
  258. * that covers the requested address @addr. If @parity is not %NULL it
  259. * is assigned the 64-bit ECC word for the read data.
  260. */
  261. int t4_mc_read(struct adapter *adap, u32 addr, __be32 *data, u64 *ecc)
  262. {
  263. int i;
  264. if (t4_read_reg(adap, MC_BIST_CMD) & START_BIST)
  265. return -EBUSY;
  266. t4_write_reg(adap, MC_BIST_CMD_ADDR, addr & ~0x3fU);
  267. t4_write_reg(adap, MC_BIST_CMD_LEN, 64);
  268. t4_write_reg(adap, MC_BIST_DATA_PATTERN, 0xc);
  269. t4_write_reg(adap, MC_BIST_CMD, BIST_OPCODE(1) | START_BIST |
  270. BIST_CMD_GAP(1));
  271. i = t4_wait_op_done(adap, MC_BIST_CMD, START_BIST, 0, 10, 1);
  272. if (i)
  273. return i;
  274. #define MC_DATA(i) MC_BIST_STATUS_REG(MC_BIST_STATUS_RDATA, i)
  275. for (i = 15; i >= 0; i--)
  276. *data++ = htonl(t4_read_reg(adap, MC_DATA(i)));
  277. if (ecc)
  278. *ecc = t4_read_reg64(adap, MC_DATA(16));
  279. #undef MC_DATA
  280. return 0;
  281. }
  282. /**
  283. * t4_edc_read - read from EDC through backdoor accesses
  284. * @adap: the adapter
  285. * @idx: which EDC to access
  286. * @addr: address of first byte requested
  287. * @data: 64 bytes of data containing the requested address
  288. * @ecc: where to store the corresponding 64-bit ECC word
  289. *
  290. * Read 64 bytes of data from EDC starting at a 64-byte-aligned address
  291. * that covers the requested address @addr. If @parity is not %NULL it
  292. * is assigned the 64-bit ECC word for the read data.
  293. */
  294. int t4_edc_read(struct adapter *adap, int idx, u32 addr, __be32 *data, u64 *ecc)
  295. {
  296. int i;
  297. idx *= EDC_STRIDE;
  298. if (t4_read_reg(adap, EDC_BIST_CMD + idx) & START_BIST)
  299. return -EBUSY;
  300. t4_write_reg(adap, EDC_BIST_CMD_ADDR + idx, addr & ~0x3fU);
  301. t4_write_reg(adap, EDC_BIST_CMD_LEN + idx, 64);
  302. t4_write_reg(adap, EDC_BIST_DATA_PATTERN + idx, 0xc);
  303. t4_write_reg(adap, EDC_BIST_CMD + idx,
  304. BIST_OPCODE(1) | BIST_CMD_GAP(1) | START_BIST);
  305. i = t4_wait_op_done(adap, EDC_BIST_CMD + idx, START_BIST, 0, 10, 1);
  306. if (i)
  307. return i;
  308. #define EDC_DATA(i) (EDC_BIST_STATUS_REG(EDC_BIST_STATUS_RDATA, i) + idx)
  309. for (i = 15; i >= 0; i--)
  310. *data++ = htonl(t4_read_reg(adap, EDC_DATA(i)));
  311. if (ecc)
  312. *ecc = t4_read_reg64(adap, EDC_DATA(16));
  313. #undef EDC_DATA
  314. return 0;
  315. }
  316. #define VPD_ENTRY(name, len) \
  317. u8 name##_kword[2]; u8 name##_len; u8 name##_data[len]
  318. /*
  319. * Partial EEPROM Vital Product Data structure. Includes only the ID and
  320. * VPD-R sections.
  321. */
  322. struct t4_vpd {
  323. u8 id_tag;
  324. u8 id_len[2];
  325. u8 id_data[ID_LEN];
  326. u8 vpdr_tag;
  327. u8 vpdr_len[2];
  328. VPD_ENTRY(pn, 16); /* part number */
  329. VPD_ENTRY(ec, EC_LEN); /* EC level */
  330. VPD_ENTRY(sn, SERNUM_LEN); /* serial number */
  331. VPD_ENTRY(na, 12); /* MAC address base */
  332. VPD_ENTRY(port_type, 8); /* port types */
  333. VPD_ENTRY(gpio, 14); /* GPIO usage */
  334. VPD_ENTRY(cclk, 6); /* core clock */
  335. VPD_ENTRY(port_addr, 8); /* port MDIO addresses */
  336. VPD_ENTRY(rv, 1); /* csum */
  337. u32 pad; /* for multiple-of-4 sizing and alignment */
  338. };
  339. #define EEPROM_STAT_ADDR 0x7bfc
  340. #define VPD_BASE 0
  341. /**
  342. * t4_seeprom_wp - enable/disable EEPROM write protection
  343. * @adapter: the adapter
  344. * @enable: whether to enable or disable write protection
  345. *
  346. * Enables or disables write protection on the serial EEPROM.
  347. */
  348. int t4_seeprom_wp(struct adapter *adapter, bool enable)
  349. {
  350. unsigned int v = enable ? 0xc : 0;
  351. int ret = pci_write_vpd(adapter->pdev, EEPROM_STAT_ADDR, 4, &v);
  352. return ret < 0 ? ret : 0;
  353. }
  354. /**
  355. * get_vpd_params - read VPD parameters from VPD EEPROM
  356. * @adapter: adapter to read
  357. * @p: where to store the parameters
  358. *
  359. * Reads card parameters stored in VPD EEPROM.
  360. */
  361. static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
  362. {
  363. int ret;
  364. struct t4_vpd vpd;
  365. u8 *q = (u8 *)&vpd, csum;
  366. ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(vpd), &vpd);
  367. if (ret < 0)
  368. return ret;
  369. for (csum = 0; q <= vpd.rv_data; q++)
  370. csum += *q;
  371. if (csum) {
  372. dev_err(adapter->pdev_dev,
  373. "corrupted VPD EEPROM, actual csum %u\n", csum);
  374. return -EINVAL;
  375. }
  376. p->cclk = simple_strtoul(vpd.cclk_data, NULL, 10);
  377. memcpy(p->id, vpd.id_data, sizeof(vpd.id_data));
  378. strim(p->id);
  379. memcpy(p->ec, vpd.ec_data, sizeof(vpd.ec_data));
  380. strim(p->ec);
  381. memcpy(p->sn, vpd.sn_data, sizeof(vpd.sn_data));
  382. strim(p->sn);
  383. return 0;
  384. }
  385. /* serial flash and firmware constants */
  386. enum {
  387. SF_ATTEMPTS = 10, /* max retries for SF operations */
  388. /* flash command opcodes */
  389. SF_PROG_PAGE = 2, /* program page */
  390. SF_WR_DISABLE = 4, /* disable writes */
  391. SF_RD_STATUS = 5, /* read status register */
  392. SF_WR_ENABLE = 6, /* enable writes */
  393. SF_RD_DATA_FAST = 0xb, /* read flash */
  394. SF_ERASE_SECTOR = 0xd8, /* erase sector */
  395. FW_START_SEC = 8, /* first flash sector for FW */
  396. FW_END_SEC = 15, /* last flash sector for FW */
  397. FW_IMG_START = FW_START_SEC * SF_SEC_SIZE,
  398. FW_MAX_SIZE = (FW_END_SEC - FW_START_SEC + 1) * SF_SEC_SIZE,
  399. };
  400. /**
  401. * sf1_read - read data from the serial flash
  402. * @adapter: the adapter
  403. * @byte_cnt: number of bytes to read
  404. * @cont: whether another operation will be chained
  405. * @lock: whether to lock SF for PL access only
  406. * @valp: where to store the read data
  407. *
  408. * Reads up to 4 bytes of data from the serial flash. The location of
  409. * the read needs to be specified prior to calling this by issuing the
  410. * appropriate commands to the serial flash.
  411. */
  412. static int sf1_read(struct adapter *adapter, unsigned int byte_cnt, int cont,
  413. int lock, u32 *valp)
  414. {
  415. int ret;
  416. if (!byte_cnt || byte_cnt > 4)
  417. return -EINVAL;
  418. if (t4_read_reg(adapter, SF_OP) & BUSY)
  419. return -EBUSY;
  420. cont = cont ? SF_CONT : 0;
  421. lock = lock ? SF_LOCK : 0;
  422. t4_write_reg(adapter, SF_OP, lock | cont | BYTECNT(byte_cnt - 1));
  423. ret = t4_wait_op_done(adapter, SF_OP, BUSY, 0, SF_ATTEMPTS, 5);
  424. if (!ret)
  425. *valp = t4_read_reg(adapter, SF_DATA);
  426. return ret;
  427. }
  428. /**
  429. * sf1_write - write data to the serial flash
  430. * @adapter: the adapter
  431. * @byte_cnt: number of bytes to write
  432. * @cont: whether another operation will be chained
  433. * @lock: whether to lock SF for PL access only
  434. * @val: value to write
  435. *
  436. * Writes up to 4 bytes of data to the serial flash. The location of
  437. * the write needs to be specified prior to calling this by issuing the
  438. * appropriate commands to the serial flash.
  439. */
  440. static int sf1_write(struct adapter *adapter, unsigned int byte_cnt, int cont,
  441. int lock, u32 val)
  442. {
  443. if (!byte_cnt || byte_cnt > 4)
  444. return -EINVAL;
  445. if (t4_read_reg(adapter, SF_OP) & BUSY)
  446. return -EBUSY;
  447. cont = cont ? SF_CONT : 0;
  448. lock = lock ? SF_LOCK : 0;
  449. t4_write_reg(adapter, SF_DATA, val);
  450. t4_write_reg(adapter, SF_OP, lock |
  451. cont | BYTECNT(byte_cnt - 1) | OP_WR);
  452. return t4_wait_op_done(adapter, SF_OP, BUSY, 0, SF_ATTEMPTS, 5);
  453. }
  454. /**
  455. * flash_wait_op - wait for a flash operation to complete
  456. * @adapter: the adapter
  457. * @attempts: max number of polls of the status register
  458. * @delay: delay between polls in ms
  459. *
  460. * Wait for a flash operation to complete by polling the status register.
  461. */
  462. static int flash_wait_op(struct adapter *adapter, int attempts, int delay)
  463. {
  464. int ret;
  465. u32 status;
  466. while (1) {
  467. if ((ret = sf1_write(adapter, 1, 1, 1, SF_RD_STATUS)) != 0 ||
  468. (ret = sf1_read(adapter, 1, 0, 1, &status)) != 0)
  469. return ret;
  470. if (!(status & 1))
  471. return 0;
  472. if (--attempts == 0)
  473. return -EAGAIN;
  474. if (delay)
  475. msleep(delay);
  476. }
  477. }
  478. /**
  479. * t4_read_flash - read words from serial flash
  480. * @adapter: the adapter
  481. * @addr: the start address for the read
  482. * @nwords: how many 32-bit words to read
  483. * @data: where to store the read data
  484. * @byte_oriented: whether to store data as bytes or as words
  485. *
  486. * Read the specified number of 32-bit words from the serial flash.
  487. * If @byte_oriented is set the read data is stored as a byte array
  488. * (i.e., big-endian), otherwise as 32-bit words in the platform's
  489. * natural endianess.
  490. */
  491. static int t4_read_flash(struct adapter *adapter, unsigned int addr,
  492. unsigned int nwords, u32 *data, int byte_oriented)
  493. {
  494. int ret;
  495. if (addr + nwords * sizeof(u32) > SF_SIZE || (addr & 3))
  496. return -EINVAL;
  497. addr = swab32(addr) | SF_RD_DATA_FAST;
  498. if ((ret = sf1_write(adapter, 4, 1, 0, addr)) != 0 ||
  499. (ret = sf1_read(adapter, 1, 1, 0, data)) != 0)
  500. return ret;
  501. for ( ; nwords; nwords--, data++) {
  502. ret = sf1_read(adapter, 4, nwords > 1, nwords == 1, data);
  503. if (nwords == 1)
  504. t4_write_reg(adapter, SF_OP, 0); /* unlock SF */
  505. if (ret)
  506. return ret;
  507. if (byte_oriented)
  508. *data = htonl(*data);
  509. }
  510. return 0;
  511. }
  512. /**
  513. * t4_write_flash - write up to a page of data to the serial flash
  514. * @adapter: the adapter
  515. * @addr: the start address to write
  516. * @n: length of data to write in bytes
  517. * @data: the data to write
  518. *
  519. * Writes up to a page of data (256 bytes) to the serial flash starting
  520. * at the given address. All the data must be written to the same page.
  521. */
  522. static int t4_write_flash(struct adapter *adapter, unsigned int addr,
  523. unsigned int n, const u8 *data)
  524. {
  525. int ret;
  526. u32 buf[64];
  527. unsigned int i, c, left, val, offset = addr & 0xff;
  528. if (addr >= SF_SIZE || offset + n > SF_PAGE_SIZE)
  529. return -EINVAL;
  530. val = swab32(addr) | SF_PROG_PAGE;
  531. if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
  532. (ret = sf1_write(adapter, 4, 1, 1, val)) != 0)
  533. goto unlock;
  534. for (left = n; left; left -= c) {
  535. c = min(left, 4U);
  536. for (val = 0, i = 0; i < c; ++i)
  537. val = (val << 8) + *data++;
  538. ret = sf1_write(adapter, c, c != left, 1, val);
  539. if (ret)
  540. goto unlock;
  541. }
  542. ret = flash_wait_op(adapter, 5, 1);
  543. if (ret)
  544. goto unlock;
  545. t4_write_reg(adapter, SF_OP, 0); /* unlock SF */
  546. /* Read the page to verify the write succeeded */
  547. ret = t4_read_flash(adapter, addr & ~0xff, ARRAY_SIZE(buf), buf, 1);
  548. if (ret)
  549. return ret;
  550. if (memcmp(data - n, (u8 *)buf + offset, n)) {
  551. dev_err(adapter->pdev_dev,
  552. "failed to correctly write the flash page at %#x\n",
  553. addr);
  554. return -EIO;
  555. }
  556. return 0;
  557. unlock:
  558. t4_write_reg(adapter, SF_OP, 0); /* unlock SF */
  559. return ret;
  560. }
  561. /**
  562. * get_fw_version - read the firmware version
  563. * @adapter: the adapter
  564. * @vers: where to place the version
  565. *
  566. * Reads the FW version from flash.
  567. */
  568. static int get_fw_version(struct adapter *adapter, u32 *vers)
  569. {
  570. return t4_read_flash(adapter,
  571. FW_IMG_START + offsetof(struct fw_hdr, fw_ver), 1,
  572. vers, 0);
  573. }
  574. /**
  575. * get_tp_version - read the TP microcode version
  576. * @adapter: the adapter
  577. * @vers: where to place the version
  578. *
  579. * Reads the TP microcode version from flash.
  580. */
  581. static int get_tp_version(struct adapter *adapter, u32 *vers)
  582. {
  583. return t4_read_flash(adapter, FW_IMG_START + offsetof(struct fw_hdr,
  584. tp_microcode_ver),
  585. 1, vers, 0);
  586. }
  587. /**
  588. * t4_check_fw_version - check if the FW is compatible with this driver
  589. * @adapter: the adapter
  590. *
  591. * Checks if an adapter's FW is compatible with the driver. Returns 0
  592. * if there's exact match, a negative error if the version could not be
  593. * read or there's a major version mismatch, and a positive value if the
  594. * expected major version is found but there's a minor version mismatch.
  595. */
  596. int t4_check_fw_version(struct adapter *adapter)
  597. {
  598. u32 api_vers[2];
  599. int ret, major, minor, micro;
  600. ret = get_fw_version(adapter, &adapter->params.fw_vers);
  601. if (!ret)
  602. ret = get_tp_version(adapter, &adapter->params.tp_vers);
  603. if (!ret)
  604. ret = t4_read_flash(adapter,
  605. FW_IMG_START + offsetof(struct fw_hdr, intfver_nic),
  606. 2, api_vers, 1);
  607. if (ret)
  608. return ret;
  609. major = FW_HDR_FW_VER_MAJOR_GET(adapter->params.fw_vers);
  610. minor = FW_HDR_FW_VER_MINOR_GET(adapter->params.fw_vers);
  611. micro = FW_HDR_FW_VER_MICRO_GET(adapter->params.fw_vers);
  612. memcpy(adapter->params.api_vers, api_vers,
  613. sizeof(adapter->params.api_vers));
  614. if (major != FW_VERSION_MAJOR) { /* major mismatch - fail */
  615. dev_err(adapter->pdev_dev,
  616. "card FW has major version %u, driver wants %u\n",
  617. major, FW_VERSION_MAJOR);
  618. return -EINVAL;
  619. }
  620. if (minor == FW_VERSION_MINOR && micro == FW_VERSION_MICRO)
  621. return 0; /* perfect match */
  622. /* Minor/micro version mismatch. Report it but often it's OK. */
  623. return 1;
  624. }
  625. /**
  626. * t4_flash_erase_sectors - erase a range of flash sectors
  627. * @adapter: the adapter
  628. * @start: the first sector to erase
  629. * @end: the last sector to erase
  630. *
  631. * Erases the sectors in the given inclusive range.
  632. */
  633. static int t4_flash_erase_sectors(struct adapter *adapter, int start, int end)
  634. {
  635. int ret = 0;
  636. while (start <= end) {
  637. if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
  638. (ret = sf1_write(adapter, 4, 0, 1,
  639. SF_ERASE_SECTOR | (start << 8))) != 0 ||
  640. (ret = flash_wait_op(adapter, 5, 500)) != 0) {
  641. dev_err(adapter->pdev_dev,
  642. "erase of flash sector %d failed, error %d\n",
  643. start, ret);
  644. break;
  645. }
  646. start++;
  647. }
  648. t4_write_reg(adapter, SF_OP, 0); /* unlock SF */
  649. return ret;
  650. }
  651. /**
  652. * t4_load_fw - download firmware
  653. * @adap: the adapter
  654. * @fw_data: the firmware image to write
  655. * @size: image size
  656. *
  657. * Write the supplied firmware image to the card's serial flash.
  658. */
  659. int t4_load_fw(struct adapter *adap, const u8 *fw_data, unsigned int size)
  660. {
  661. u32 csum;
  662. int ret, addr;
  663. unsigned int i;
  664. u8 first_page[SF_PAGE_SIZE];
  665. const u32 *p = (const u32 *)fw_data;
  666. const struct fw_hdr *hdr = (const struct fw_hdr *)fw_data;
  667. if (!size) {
  668. dev_err(adap->pdev_dev, "FW image has no data\n");
  669. return -EINVAL;
  670. }
  671. if (size & 511) {
  672. dev_err(adap->pdev_dev,
  673. "FW image size not multiple of 512 bytes\n");
  674. return -EINVAL;
  675. }
  676. if (ntohs(hdr->len512) * 512 != size) {
  677. dev_err(adap->pdev_dev,
  678. "FW image size differs from size in FW header\n");
  679. return -EINVAL;
  680. }
  681. if (size > FW_MAX_SIZE) {
  682. dev_err(adap->pdev_dev, "FW image too large, max is %u bytes\n",
  683. FW_MAX_SIZE);
  684. return -EFBIG;
  685. }
  686. for (csum = 0, i = 0; i < size / sizeof(csum); i++)
  687. csum += ntohl(p[i]);
  688. if (csum != 0xffffffff) {
  689. dev_err(adap->pdev_dev,
  690. "corrupted firmware image, checksum %#x\n", csum);
  691. return -EINVAL;
  692. }
  693. i = DIV_ROUND_UP(size, SF_SEC_SIZE); /* # of sectors spanned */
  694. ret = t4_flash_erase_sectors(adap, FW_START_SEC, FW_START_SEC + i - 1);
  695. if (ret)
  696. goto out;
  697. /*
  698. * We write the correct version at the end so the driver can see a bad
  699. * version if the FW write fails. Start by writing a copy of the
  700. * first page with a bad version.
  701. */
  702. memcpy(first_page, fw_data, SF_PAGE_SIZE);
  703. ((struct fw_hdr *)first_page)->fw_ver = htonl(0xffffffff);
  704. ret = t4_write_flash(adap, FW_IMG_START, SF_PAGE_SIZE, first_page);
  705. if (ret)
  706. goto out;
  707. addr = FW_IMG_START;
  708. for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) {
  709. addr += SF_PAGE_SIZE;
  710. fw_data += SF_PAGE_SIZE;
  711. ret = t4_write_flash(adap, addr, SF_PAGE_SIZE, fw_data);
  712. if (ret)
  713. goto out;
  714. }
  715. ret = t4_write_flash(adap,
  716. FW_IMG_START + offsetof(struct fw_hdr, fw_ver),
  717. sizeof(hdr->fw_ver), (const u8 *)&hdr->fw_ver);
  718. out:
  719. if (ret)
  720. dev_err(adap->pdev_dev, "firmware download failed, error %d\n",
  721. ret);
  722. return ret;
  723. }
  724. #define ADVERT_MASK (FW_PORT_CAP_SPEED_100M | FW_PORT_CAP_SPEED_1G |\
  725. FW_PORT_CAP_SPEED_10G | FW_PORT_CAP_ANEG)
  726. /**
  727. * t4_link_start - apply link configuration to MAC/PHY
  728. * @phy: the PHY to setup
  729. * @mac: the MAC to setup
  730. * @lc: the requested link configuration
  731. *
  732. * Set up a port's MAC and PHY according to a desired link configuration.
  733. * - If the PHY can auto-negotiate first decide what to advertise, then
  734. * enable/disable auto-negotiation as desired, and reset.
  735. * - If the PHY does not auto-negotiate just reset it.
  736. * - If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
  737. * otherwise do it later based on the outcome of auto-negotiation.
  738. */
  739. int t4_link_start(struct adapter *adap, unsigned int mbox, unsigned int port,
  740. struct link_config *lc)
  741. {
  742. struct fw_port_cmd c;
  743. unsigned int fc = 0, mdi = FW_PORT_MDI(FW_PORT_MDI_AUTO);
  744. lc->link_ok = 0;
  745. if (lc->requested_fc & PAUSE_RX)
  746. fc |= FW_PORT_CAP_FC_RX;
  747. if (lc->requested_fc & PAUSE_TX)
  748. fc |= FW_PORT_CAP_FC_TX;
  749. memset(&c, 0, sizeof(c));
  750. c.op_to_portid = htonl(FW_CMD_OP(FW_PORT_CMD) | FW_CMD_REQUEST |
  751. FW_CMD_EXEC | FW_PORT_CMD_PORTID(port));
  752. c.action_to_len16 = htonl(FW_PORT_CMD_ACTION(FW_PORT_ACTION_L1_CFG) |
  753. FW_LEN16(c));
  754. if (!(lc->supported & FW_PORT_CAP_ANEG)) {
  755. c.u.l1cfg.rcap = htonl((lc->supported & ADVERT_MASK) | fc);
  756. lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  757. } else if (lc->autoneg == AUTONEG_DISABLE) {
  758. c.u.l1cfg.rcap = htonl(lc->requested_speed | fc | mdi);
  759. lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  760. } else
  761. c.u.l1cfg.rcap = htonl(lc->advertising | fc | mdi);
  762. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  763. }
  764. /**
  765. * t4_restart_aneg - restart autonegotiation
  766. * @adap: the adapter
  767. * @mbox: mbox to use for the FW command
  768. * @port: the port id
  769. *
  770. * Restarts autonegotiation for the selected port.
  771. */
  772. int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port)
  773. {
  774. struct fw_port_cmd c;
  775. memset(&c, 0, sizeof(c));
  776. c.op_to_portid = htonl(FW_CMD_OP(FW_PORT_CMD) | FW_CMD_REQUEST |
  777. FW_CMD_EXEC | FW_PORT_CMD_PORTID(port));
  778. c.action_to_len16 = htonl(FW_PORT_CMD_ACTION(FW_PORT_ACTION_L1_CFG) |
  779. FW_LEN16(c));
  780. c.u.l1cfg.rcap = htonl(FW_PORT_CAP_ANEG);
  781. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  782. }
  783. /**
  784. * t4_set_vlan_accel - configure HW VLAN extraction
  785. * @adap: the adapter
  786. * @ports: bitmap of adapter ports to operate on
  787. * @on: enable (1) or disable (0) HW VLAN extraction
  788. *
  789. * Enables or disables HW extraction of VLAN tags for the ports specified
  790. * by @ports. @ports is a bitmap with the ith bit designating the port
  791. * associated with the ith adapter channel.
  792. */
  793. void t4_set_vlan_accel(struct adapter *adap, unsigned int ports, int on)
  794. {
  795. ports <<= VLANEXTENABLE_SHIFT;
  796. t4_set_reg_field(adap, TP_OUT_CONFIG, ports, on ? ports : 0);
  797. }
  798. struct intr_info {
  799. unsigned int mask; /* bits to check in interrupt status */
  800. const char *msg; /* message to print or NULL */
  801. short stat_idx; /* stat counter to increment or -1 */
  802. unsigned short fatal; /* whether the condition reported is fatal */
  803. };
  804. /**
  805. * t4_handle_intr_status - table driven interrupt handler
  806. * @adapter: the adapter that generated the interrupt
  807. * @reg: the interrupt status register to process
  808. * @acts: table of interrupt actions
  809. *
  810. * A table driven interrupt handler that applies a set of masks to an
  811. * interrupt status word and performs the corresponding actions if the
  812. * interrupts described by the mask have occured. The actions include
  813. * optionally emitting a warning or alert message. The table is terminated
  814. * by an entry specifying mask 0. Returns the number of fatal interrupt
  815. * conditions.
  816. */
  817. static int t4_handle_intr_status(struct adapter *adapter, unsigned int reg,
  818. const struct intr_info *acts)
  819. {
  820. int fatal = 0;
  821. unsigned int mask = 0;
  822. unsigned int status = t4_read_reg(adapter, reg);
  823. for ( ; acts->mask; ++acts) {
  824. if (!(status & acts->mask))
  825. continue;
  826. if (acts->fatal) {
  827. fatal++;
  828. dev_alert(adapter->pdev_dev, "%s (0x%x)\n", acts->msg,
  829. status & acts->mask);
  830. } else if (acts->msg && printk_ratelimit())
  831. dev_warn(adapter->pdev_dev, "%s (0x%x)\n", acts->msg,
  832. status & acts->mask);
  833. mask |= acts->mask;
  834. }
  835. status &= mask;
  836. if (status) /* clear processed interrupts */
  837. t4_write_reg(adapter, reg, status);
  838. return fatal;
  839. }
  840. /*
  841. * Interrupt handler for the PCIE module.
  842. */
  843. static void pcie_intr_handler(struct adapter *adapter)
  844. {
  845. static struct intr_info sysbus_intr_info[] = {
  846. { RNPP, "RXNP array parity error", -1, 1 },
  847. { RPCP, "RXPC array parity error", -1, 1 },
  848. { RCIP, "RXCIF array parity error", -1, 1 },
  849. { RCCP, "Rx completions control array parity error", -1, 1 },
  850. { RFTP, "RXFT array parity error", -1, 1 },
  851. { 0 }
  852. };
  853. static struct intr_info pcie_port_intr_info[] = {
  854. { TPCP, "TXPC array parity error", -1, 1 },
  855. { TNPP, "TXNP array parity error", -1, 1 },
  856. { TFTP, "TXFT array parity error", -1, 1 },
  857. { TCAP, "TXCA array parity error", -1, 1 },
  858. { TCIP, "TXCIF array parity error", -1, 1 },
  859. { RCAP, "RXCA array parity error", -1, 1 },
  860. { OTDD, "outbound request TLP discarded", -1, 1 },
  861. { RDPE, "Rx data parity error", -1, 1 },
  862. { TDUE, "Tx uncorrectable data error", -1, 1 },
  863. { 0 }
  864. };
  865. static struct intr_info pcie_intr_info[] = {
  866. { MSIADDRLPERR, "MSI AddrL parity error", -1, 1 },
  867. { MSIADDRHPERR, "MSI AddrH parity error", -1, 1 },
  868. { MSIDATAPERR, "MSI data parity error", -1, 1 },
  869. { MSIXADDRLPERR, "MSI-X AddrL parity error", -1, 1 },
  870. { MSIXADDRHPERR, "MSI-X AddrH parity error", -1, 1 },
  871. { MSIXDATAPERR, "MSI-X data parity error", -1, 1 },
  872. { MSIXDIPERR, "MSI-X DI parity error", -1, 1 },
  873. { PIOCPLPERR, "PCI PIO completion FIFO parity error", -1, 1 },
  874. { PIOREQPERR, "PCI PIO request FIFO parity error", -1, 1 },
  875. { TARTAGPERR, "PCI PCI target tag FIFO parity error", -1, 1 },
  876. { CCNTPERR, "PCI CMD channel count parity error", -1, 1 },
  877. { CREQPERR, "PCI CMD channel request parity error", -1, 1 },
  878. { CRSPPERR, "PCI CMD channel response parity error", -1, 1 },
  879. { DCNTPERR, "PCI DMA channel count parity error", -1, 1 },
  880. { DREQPERR, "PCI DMA channel request parity error", -1, 1 },
  881. { DRSPPERR, "PCI DMA channel response parity error", -1, 1 },
  882. { HCNTPERR, "PCI HMA channel count parity error", -1, 1 },
  883. { HREQPERR, "PCI HMA channel request parity error", -1, 1 },
  884. { HRSPPERR, "PCI HMA channel response parity error", -1, 1 },
  885. { CFGSNPPERR, "PCI config snoop FIFO parity error", -1, 1 },
  886. { FIDPERR, "PCI FID parity error", -1, 1 },
  887. { INTXCLRPERR, "PCI INTx clear parity error", -1, 1 },
  888. { MATAGPERR, "PCI MA tag parity error", -1, 1 },
  889. { PIOTAGPERR, "PCI PIO tag parity error", -1, 1 },
  890. { RXCPLPERR, "PCI Rx completion parity error", -1, 1 },
  891. { RXWRPERR, "PCI Rx write parity error", -1, 1 },
  892. { RPLPERR, "PCI replay buffer parity error", -1, 1 },
  893. { PCIESINT, "PCI core secondary fault", -1, 1 },
  894. { PCIEPINT, "PCI core primary fault", -1, 1 },
  895. { UNXSPLCPLERR, "PCI unexpected split completion error", -1, 0 },
  896. { 0 }
  897. };
  898. int fat;
  899. fat = t4_handle_intr_status(adapter,
  900. PCIE_CORE_UTL_SYSTEM_BUS_AGENT_STATUS,
  901. sysbus_intr_info) +
  902. t4_handle_intr_status(adapter,
  903. PCIE_CORE_UTL_PCI_EXPRESS_PORT_STATUS,
  904. pcie_port_intr_info) +
  905. t4_handle_intr_status(adapter, PCIE_INT_CAUSE, pcie_intr_info);
  906. if (fat)
  907. t4_fatal_err(adapter);
  908. }
  909. /*
  910. * TP interrupt handler.
  911. */
  912. static void tp_intr_handler(struct adapter *adapter)
  913. {
  914. static struct intr_info tp_intr_info[] = {
  915. { 0x3fffffff, "TP parity error", -1, 1 },
  916. { FLMTXFLSTEMPTY, "TP out of Tx pages", -1, 1 },
  917. { 0 }
  918. };
  919. if (t4_handle_intr_status(adapter, TP_INT_CAUSE, tp_intr_info))
  920. t4_fatal_err(adapter);
  921. }
  922. /*
  923. * SGE interrupt handler.
  924. */
  925. static void sge_intr_handler(struct adapter *adapter)
  926. {
  927. u64 v;
  928. static struct intr_info sge_intr_info[] = {
  929. { ERR_CPL_EXCEED_IQE_SIZE,
  930. "SGE received CPL exceeding IQE size", -1, 1 },
  931. { ERR_INVALID_CIDX_INC,
  932. "SGE GTS CIDX increment too large", -1, 0 },
  933. { ERR_CPL_OPCODE_0, "SGE received 0-length CPL", -1, 0 },
  934. { ERR_DROPPED_DB, "SGE doorbell dropped", -1, 0 },
  935. { ERR_DATA_CPL_ON_HIGH_QID1 | ERR_DATA_CPL_ON_HIGH_QID0,
  936. "SGE IQID > 1023 received CPL for FL", -1, 0 },
  937. { ERR_BAD_DB_PIDX3, "SGE DBP 3 pidx increment too large", -1,
  938. 0 },
  939. { ERR_BAD_DB_PIDX2, "SGE DBP 2 pidx increment too large", -1,
  940. 0 },
  941. { ERR_BAD_DB_PIDX1, "SGE DBP 1 pidx increment too large", -1,
  942. 0 },
  943. { ERR_BAD_DB_PIDX0, "SGE DBP 0 pidx increment too large", -1,
  944. 0 },
  945. { ERR_ING_CTXT_PRIO,
  946. "SGE too many priority ingress contexts", -1, 0 },
  947. { ERR_EGR_CTXT_PRIO,
  948. "SGE too many priority egress contexts", -1, 0 },
  949. { INGRESS_SIZE_ERR, "SGE illegal ingress QID", -1, 0 },
  950. { EGRESS_SIZE_ERR, "SGE illegal egress QID", -1, 0 },
  951. { 0 }
  952. };
  953. v = (u64)t4_read_reg(adapter, SGE_INT_CAUSE1) |
  954. ((u64)t4_read_reg(adapter, SGE_INT_CAUSE2) << 32);
  955. if (v) {
  956. dev_alert(adapter->pdev_dev, "SGE parity error (%#llx)\n",
  957. (unsigned long long)v);
  958. t4_write_reg(adapter, SGE_INT_CAUSE1, v);
  959. t4_write_reg(adapter, SGE_INT_CAUSE2, v >> 32);
  960. }
  961. if (t4_handle_intr_status(adapter, SGE_INT_CAUSE3, sge_intr_info) ||
  962. v != 0)
  963. t4_fatal_err(adapter);
  964. }
  965. /*
  966. * CIM interrupt handler.
  967. */
  968. static void cim_intr_handler(struct adapter *adapter)
  969. {
  970. static struct intr_info cim_intr_info[] = {
  971. { PREFDROPINT, "CIM control register prefetch drop", -1, 1 },
  972. { OBQPARERR, "CIM OBQ parity error", -1, 1 },
  973. { IBQPARERR, "CIM IBQ parity error", -1, 1 },
  974. { MBUPPARERR, "CIM mailbox uP parity error", -1, 1 },
  975. { MBHOSTPARERR, "CIM mailbox host parity error", -1, 1 },
  976. { TIEQINPARERRINT, "CIM TIEQ outgoing parity error", -1, 1 },
  977. { TIEQOUTPARERRINT, "CIM TIEQ incoming parity error", -1, 1 },
  978. { 0 }
  979. };
  980. static struct intr_info cim_upintr_info[] = {
  981. { RSVDSPACEINT, "CIM reserved space access", -1, 1 },
  982. { ILLTRANSINT, "CIM illegal transaction", -1, 1 },
  983. { ILLWRINT, "CIM illegal write", -1, 1 },
  984. { ILLRDINT, "CIM illegal read", -1, 1 },
  985. { ILLRDBEINT, "CIM illegal read BE", -1, 1 },
  986. { ILLWRBEINT, "CIM illegal write BE", -1, 1 },
  987. { SGLRDBOOTINT, "CIM single read from boot space", -1, 1 },
  988. { SGLWRBOOTINT, "CIM single write to boot space", -1, 1 },
  989. { BLKWRBOOTINT, "CIM block write to boot space", -1, 1 },
  990. { SGLRDFLASHINT, "CIM single read from flash space", -1, 1 },
  991. { SGLWRFLASHINT, "CIM single write to flash space", -1, 1 },
  992. { BLKWRFLASHINT, "CIM block write to flash space", -1, 1 },
  993. { SGLRDEEPROMINT, "CIM single EEPROM read", -1, 1 },
  994. { SGLWREEPROMINT, "CIM single EEPROM write", -1, 1 },
  995. { BLKRDEEPROMINT, "CIM block EEPROM read", -1, 1 },
  996. { BLKWREEPROMINT, "CIM block EEPROM write", -1, 1 },
  997. { SGLRDCTLINT , "CIM single read from CTL space", -1, 1 },
  998. { SGLWRCTLINT , "CIM single write to CTL space", -1, 1 },
  999. { BLKRDCTLINT , "CIM block read from CTL space", -1, 1 },
  1000. { BLKWRCTLINT , "CIM block write to CTL space", -1, 1 },
  1001. { SGLRDPLINT , "CIM single read from PL space", -1, 1 },
  1002. { SGLWRPLINT , "CIM single write to PL space", -1, 1 },
  1003. { BLKRDPLINT , "CIM block read from PL space", -1, 1 },
  1004. { BLKWRPLINT , "CIM block write to PL space", -1, 1 },
  1005. { REQOVRLOOKUPINT , "CIM request FIFO overwrite", -1, 1 },
  1006. { RSPOVRLOOKUPINT , "CIM response FIFO overwrite", -1, 1 },
  1007. { TIMEOUTINT , "CIM PIF timeout", -1, 1 },
  1008. { TIMEOUTMAINT , "CIM PIF MA timeout", -1, 1 },
  1009. { 0 }
  1010. };
  1011. int fat;
  1012. fat = t4_handle_intr_status(adapter, CIM_HOST_INT_CAUSE,
  1013. cim_intr_info) +
  1014. t4_handle_intr_status(adapter, CIM_HOST_UPACC_INT_CAUSE,
  1015. cim_upintr_info);
  1016. if (fat)
  1017. t4_fatal_err(adapter);
  1018. }
  1019. /*
  1020. * ULP RX interrupt handler.
  1021. */
  1022. static void ulprx_intr_handler(struct adapter *adapter)
  1023. {
  1024. static struct intr_info ulprx_intr_info[] = {
  1025. { 0x7fffff, "ULPRX parity error", -1, 1 },
  1026. { 0 }
  1027. };
  1028. if (t4_handle_intr_status(adapter, ULP_RX_INT_CAUSE, ulprx_intr_info))
  1029. t4_fatal_err(adapter);
  1030. }
  1031. /*
  1032. * ULP TX interrupt handler.
  1033. */
  1034. static void ulptx_intr_handler(struct adapter *adapter)
  1035. {
  1036. static struct intr_info ulptx_intr_info[] = {
  1037. { PBL_BOUND_ERR_CH3, "ULPTX channel 3 PBL out of bounds", -1,
  1038. 0 },
  1039. { PBL_BOUND_ERR_CH2, "ULPTX channel 2 PBL out of bounds", -1,
  1040. 0 },
  1041. { PBL_BOUND_ERR_CH1, "ULPTX channel 1 PBL out of bounds", -1,
  1042. 0 },
  1043. { PBL_BOUND_ERR_CH0, "ULPTX channel 0 PBL out of bounds", -1,
  1044. 0 },
  1045. { 0xfffffff, "ULPTX parity error", -1, 1 },
  1046. { 0 }
  1047. };
  1048. if (t4_handle_intr_status(adapter, ULP_TX_INT_CAUSE, ulptx_intr_info))
  1049. t4_fatal_err(adapter);
  1050. }
  1051. /*
  1052. * PM TX interrupt handler.
  1053. */
  1054. static void pmtx_intr_handler(struct adapter *adapter)
  1055. {
  1056. static struct intr_info pmtx_intr_info[] = {
  1057. { PCMD_LEN_OVFL0, "PMTX channel 0 pcmd too large", -1, 1 },
  1058. { PCMD_LEN_OVFL1, "PMTX channel 1 pcmd too large", -1, 1 },
  1059. { PCMD_LEN_OVFL2, "PMTX channel 2 pcmd too large", -1, 1 },
  1060. { ZERO_C_CMD_ERROR, "PMTX 0-length pcmd", -1, 1 },
  1061. { PMTX_FRAMING_ERROR, "PMTX framing error", -1, 1 },
  1062. { OESPI_PAR_ERROR, "PMTX oespi parity error", -1, 1 },
  1063. { DB_OPTIONS_PAR_ERROR, "PMTX db_options parity error", -1, 1 },
  1064. { ICSPI_PAR_ERROR, "PMTX icspi parity error", -1, 1 },
  1065. { C_PCMD_PAR_ERROR, "PMTX c_pcmd parity error", -1, 1},
  1066. { 0 }
  1067. };
  1068. if (t4_handle_intr_status(adapter, PM_TX_INT_CAUSE, pmtx_intr_info))
  1069. t4_fatal_err(adapter);
  1070. }
  1071. /*
  1072. * PM RX interrupt handler.
  1073. */
  1074. static void pmrx_intr_handler(struct adapter *adapter)
  1075. {
  1076. static struct intr_info pmrx_intr_info[] = {
  1077. { ZERO_E_CMD_ERROR, "PMRX 0-length pcmd", -1, 1 },
  1078. { PMRX_FRAMING_ERROR, "PMRX framing error", -1, 1 },
  1079. { OCSPI_PAR_ERROR, "PMRX ocspi parity error", -1, 1 },
  1080. { DB_OPTIONS_PAR_ERROR, "PMRX db_options parity error", -1, 1 },
  1081. { IESPI_PAR_ERROR, "PMRX iespi parity error", -1, 1 },
  1082. { E_PCMD_PAR_ERROR, "PMRX e_pcmd parity error", -1, 1},
  1083. { 0 }
  1084. };
  1085. if (t4_handle_intr_status(adapter, PM_RX_INT_CAUSE, pmrx_intr_info))
  1086. t4_fatal_err(adapter);
  1087. }
  1088. /*
  1089. * CPL switch interrupt handler.
  1090. */
  1091. static void cplsw_intr_handler(struct adapter *adapter)
  1092. {
  1093. static struct intr_info cplsw_intr_info[] = {
  1094. { CIM_OP_MAP_PERR, "CPLSW CIM op_map parity error", -1, 1 },
  1095. { CIM_OVFL_ERROR, "CPLSW CIM overflow", -1, 1 },
  1096. { TP_FRAMING_ERROR, "CPLSW TP framing error", -1, 1 },
  1097. { SGE_FRAMING_ERROR, "CPLSW SGE framing error", -1, 1 },
  1098. { CIM_FRAMING_ERROR, "CPLSW CIM framing error", -1, 1 },
  1099. { ZERO_SWITCH_ERROR, "CPLSW no-switch error", -1, 1 },
  1100. { 0 }
  1101. };
  1102. if (t4_handle_intr_status(adapter, CPL_INTR_CAUSE, cplsw_intr_info))
  1103. t4_fatal_err(adapter);
  1104. }
  1105. /*
  1106. * LE interrupt handler.
  1107. */
  1108. static void le_intr_handler(struct adapter *adap)
  1109. {
  1110. static struct intr_info le_intr_info[] = {
  1111. { LIPMISS, "LE LIP miss", -1, 0 },
  1112. { LIP0, "LE 0 LIP error", -1, 0 },
  1113. { PARITYERR, "LE parity error", -1, 1 },
  1114. { UNKNOWNCMD, "LE unknown command", -1, 1 },
  1115. { REQQPARERR, "LE request queue parity error", -1, 1 },
  1116. { 0 }
  1117. };
  1118. if (t4_handle_intr_status(adap, LE_DB_INT_CAUSE, le_intr_info))
  1119. t4_fatal_err(adap);
  1120. }
  1121. /*
  1122. * MPS interrupt handler.
  1123. */
  1124. static void mps_intr_handler(struct adapter *adapter)
  1125. {
  1126. static struct intr_info mps_rx_intr_info[] = {
  1127. { 0xffffff, "MPS Rx parity error", -1, 1 },
  1128. { 0 }
  1129. };
  1130. static struct intr_info mps_tx_intr_info[] = {
  1131. { TPFIFO, "MPS Tx TP FIFO parity error", -1, 1 },
  1132. { NCSIFIFO, "MPS Tx NC-SI FIFO parity error", -1, 1 },
  1133. { TXDATAFIFO, "MPS Tx data FIFO parity error", -1, 1 },
  1134. { TXDESCFIFO, "MPS Tx desc FIFO parity error", -1, 1 },
  1135. { BUBBLE, "MPS Tx underflow", -1, 1 },
  1136. { SECNTERR, "MPS Tx SOP/EOP error", -1, 1 },
  1137. { FRMERR, "MPS Tx framing error", -1, 1 },
  1138. { 0 }
  1139. };
  1140. static struct intr_info mps_trc_intr_info[] = {
  1141. { FILTMEM, "MPS TRC filter parity error", -1, 1 },
  1142. { PKTFIFO, "MPS TRC packet FIFO parity error", -1, 1 },
  1143. { MISCPERR, "MPS TRC misc parity error", -1, 1 },
  1144. { 0 }
  1145. };
  1146. static struct intr_info mps_stat_sram_intr_info[] = {
  1147. { 0x1fffff, "MPS statistics SRAM parity error", -1, 1 },
  1148. { 0 }
  1149. };
  1150. static struct intr_info mps_stat_tx_intr_info[] = {
  1151. { 0xfffff, "MPS statistics Tx FIFO parity error", -1, 1 },
  1152. { 0 }
  1153. };
  1154. static struct intr_info mps_stat_rx_intr_info[] = {
  1155. { 0xffffff, "MPS statistics Rx FIFO parity error", -1, 1 },
  1156. { 0 }
  1157. };
  1158. static struct intr_info mps_cls_intr_info[] = {
  1159. { MATCHSRAM, "MPS match SRAM parity error", -1, 1 },
  1160. { MATCHTCAM, "MPS match TCAM parity error", -1, 1 },
  1161. { HASHSRAM, "MPS hash SRAM parity error", -1, 1 },
  1162. { 0 }
  1163. };
  1164. int fat;
  1165. fat = t4_handle_intr_status(adapter, MPS_RX_PERR_INT_CAUSE,
  1166. mps_rx_intr_info) +
  1167. t4_handle_intr_status(adapter, MPS_TX_INT_CAUSE,
  1168. mps_tx_intr_info) +
  1169. t4_handle_intr_status(adapter, MPS_TRC_INT_CAUSE,
  1170. mps_trc_intr_info) +
  1171. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_SRAM,
  1172. mps_stat_sram_intr_info) +
  1173. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_TX_FIFO,
  1174. mps_stat_tx_intr_info) +
  1175. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_RX_FIFO,
  1176. mps_stat_rx_intr_info) +
  1177. t4_handle_intr_status(adapter, MPS_CLS_INT_CAUSE,
  1178. mps_cls_intr_info);
  1179. t4_write_reg(adapter, MPS_INT_CAUSE, CLSINT | TRCINT |
  1180. RXINT | TXINT | STATINT);
  1181. t4_read_reg(adapter, MPS_INT_CAUSE); /* flush */
  1182. if (fat)
  1183. t4_fatal_err(adapter);
  1184. }
  1185. #define MEM_INT_MASK (PERR_INT_CAUSE | ECC_CE_INT_CAUSE | ECC_UE_INT_CAUSE)
  1186. /*
  1187. * EDC/MC interrupt handler.
  1188. */
  1189. static void mem_intr_handler(struct adapter *adapter, int idx)
  1190. {
  1191. static const char name[3][5] = { "EDC0", "EDC1", "MC" };
  1192. unsigned int addr, cnt_addr, v;
  1193. if (idx <= MEM_EDC1) {
  1194. addr = EDC_REG(EDC_INT_CAUSE, idx);
  1195. cnt_addr = EDC_REG(EDC_ECC_STATUS, idx);
  1196. } else {
  1197. addr = MC_INT_CAUSE;
  1198. cnt_addr = MC_ECC_STATUS;
  1199. }
  1200. v = t4_read_reg(adapter, addr) & MEM_INT_MASK;
  1201. if (v & PERR_INT_CAUSE)
  1202. dev_alert(adapter->pdev_dev, "%s FIFO parity error\n",
  1203. name[idx]);
  1204. if (v & ECC_CE_INT_CAUSE) {
  1205. u32 cnt = ECC_CECNT_GET(t4_read_reg(adapter, cnt_addr));
  1206. t4_write_reg(adapter, cnt_addr, ECC_CECNT_MASK);
  1207. if (printk_ratelimit())
  1208. dev_warn(adapter->pdev_dev,
  1209. "%u %s correctable ECC data error%s\n",
  1210. cnt, name[idx], cnt > 1 ? "s" : "");
  1211. }
  1212. if (v & ECC_UE_INT_CAUSE)
  1213. dev_alert(adapter->pdev_dev,
  1214. "%s uncorrectable ECC data error\n", name[idx]);
  1215. t4_write_reg(adapter, addr, v);
  1216. if (v & (PERR_INT_CAUSE | ECC_UE_INT_CAUSE))
  1217. t4_fatal_err(adapter);
  1218. }
  1219. /*
  1220. * MA interrupt handler.
  1221. */
  1222. static void ma_intr_handler(struct adapter *adap)
  1223. {
  1224. u32 v, status = t4_read_reg(adap, MA_INT_CAUSE);
  1225. if (status & MEM_PERR_INT_CAUSE)
  1226. dev_alert(adap->pdev_dev,
  1227. "MA parity error, parity status %#x\n",
  1228. t4_read_reg(adap, MA_PARITY_ERROR_STATUS));
  1229. if (status & MEM_WRAP_INT_CAUSE) {
  1230. v = t4_read_reg(adap, MA_INT_WRAP_STATUS);
  1231. dev_alert(adap->pdev_dev, "MA address wrap-around error by "
  1232. "client %u to address %#x\n",
  1233. MEM_WRAP_CLIENT_NUM_GET(v),
  1234. MEM_WRAP_ADDRESS_GET(v) << 4);
  1235. }
  1236. t4_write_reg(adap, MA_INT_CAUSE, status);
  1237. t4_fatal_err(adap);
  1238. }
  1239. /*
  1240. * SMB interrupt handler.
  1241. */
  1242. static void smb_intr_handler(struct adapter *adap)
  1243. {
  1244. static struct intr_info smb_intr_info[] = {
  1245. { MSTTXFIFOPARINT, "SMB master Tx FIFO parity error", -1, 1 },
  1246. { MSTRXFIFOPARINT, "SMB master Rx FIFO parity error", -1, 1 },
  1247. { SLVFIFOPARINT, "SMB slave FIFO parity error", -1, 1 },
  1248. { 0 }
  1249. };
  1250. if (t4_handle_intr_status(adap, SMB_INT_CAUSE, smb_intr_info))
  1251. t4_fatal_err(adap);
  1252. }
  1253. /*
  1254. * NC-SI interrupt handler.
  1255. */
  1256. static void ncsi_intr_handler(struct adapter *adap)
  1257. {
  1258. static struct intr_info ncsi_intr_info[] = {
  1259. { CIM_DM_PRTY_ERR, "NC-SI CIM parity error", -1, 1 },
  1260. { MPS_DM_PRTY_ERR, "NC-SI MPS parity error", -1, 1 },
  1261. { TXFIFO_PRTY_ERR, "NC-SI Tx FIFO parity error", -1, 1 },
  1262. { RXFIFO_PRTY_ERR, "NC-SI Rx FIFO parity error", -1, 1 },
  1263. { 0 }
  1264. };
  1265. if (t4_handle_intr_status(adap, NCSI_INT_CAUSE, ncsi_intr_info))
  1266. t4_fatal_err(adap);
  1267. }
  1268. /*
  1269. * XGMAC interrupt handler.
  1270. */
  1271. static void xgmac_intr_handler(struct adapter *adap, int port)
  1272. {
  1273. u32 v = t4_read_reg(adap, PORT_REG(port, XGMAC_PORT_INT_CAUSE));
  1274. v &= TXFIFO_PRTY_ERR | RXFIFO_PRTY_ERR;
  1275. if (!v)
  1276. return;
  1277. if (v & TXFIFO_PRTY_ERR)
  1278. dev_alert(adap->pdev_dev, "XGMAC %d Tx FIFO parity error\n",
  1279. port);
  1280. if (v & RXFIFO_PRTY_ERR)
  1281. dev_alert(adap->pdev_dev, "XGMAC %d Rx FIFO parity error\n",
  1282. port);
  1283. t4_write_reg(adap, PORT_REG(port, XGMAC_PORT_INT_CAUSE), v);
  1284. t4_fatal_err(adap);
  1285. }
  1286. /*
  1287. * PL interrupt handler.
  1288. */
  1289. static void pl_intr_handler(struct adapter *adap)
  1290. {
  1291. static struct intr_info pl_intr_info[] = {
  1292. { FATALPERR, "T4 fatal parity error", -1, 1 },
  1293. { PERRVFID, "PL VFID_MAP parity error", -1, 1 },
  1294. { 0 }
  1295. };
  1296. if (t4_handle_intr_status(adap, PL_PL_INT_CAUSE, pl_intr_info))
  1297. t4_fatal_err(adap);
  1298. }
  1299. #define PF_INTR_MASK (PFSW | PFCIM)
  1300. #define GLBL_INTR_MASK (CIM | MPS | PL | PCIE | MC | EDC0 | \
  1301. EDC1 | LE | TP | MA | PM_TX | PM_RX | ULP_RX | \
  1302. CPL_SWITCH | SGE | ULP_TX)
  1303. /**
  1304. * t4_slow_intr_handler - control path interrupt handler
  1305. * @adapter: the adapter
  1306. *
  1307. * T4 interrupt handler for non-data global interrupt events, e.g., errors.
  1308. * The designation 'slow' is because it involves register reads, while
  1309. * data interrupts typically don't involve any MMIOs.
  1310. */
  1311. int t4_slow_intr_handler(struct adapter *adapter)
  1312. {
  1313. u32 cause = t4_read_reg(adapter, PL_INT_CAUSE);
  1314. if (!(cause & GLBL_INTR_MASK))
  1315. return 0;
  1316. if (cause & CIM)
  1317. cim_intr_handler(adapter);
  1318. if (cause & MPS)
  1319. mps_intr_handler(adapter);
  1320. if (cause & NCSI)
  1321. ncsi_intr_handler(adapter);
  1322. if (cause & PL)
  1323. pl_intr_handler(adapter);
  1324. if (cause & SMB)
  1325. smb_intr_handler(adapter);
  1326. if (cause & XGMAC0)
  1327. xgmac_intr_handler(adapter, 0);
  1328. if (cause & XGMAC1)
  1329. xgmac_intr_handler(adapter, 1);
  1330. if (cause & XGMAC_KR0)
  1331. xgmac_intr_handler(adapter, 2);
  1332. if (cause & XGMAC_KR1)
  1333. xgmac_intr_handler(adapter, 3);
  1334. if (cause & PCIE)
  1335. pcie_intr_handler(adapter);
  1336. if (cause & MC)
  1337. mem_intr_handler(adapter, MEM_MC);
  1338. if (cause & EDC0)
  1339. mem_intr_handler(adapter, MEM_EDC0);
  1340. if (cause & EDC1)
  1341. mem_intr_handler(adapter, MEM_EDC1);
  1342. if (cause & LE)
  1343. le_intr_handler(adapter);
  1344. if (cause & TP)
  1345. tp_intr_handler(adapter);
  1346. if (cause & MA)
  1347. ma_intr_handler(adapter);
  1348. if (cause & PM_TX)
  1349. pmtx_intr_handler(adapter);
  1350. if (cause & PM_RX)
  1351. pmrx_intr_handler(adapter);
  1352. if (cause & ULP_RX)
  1353. ulprx_intr_handler(adapter);
  1354. if (cause & CPL_SWITCH)
  1355. cplsw_intr_handler(adapter);
  1356. if (cause & SGE)
  1357. sge_intr_handler(adapter);
  1358. if (cause & ULP_TX)
  1359. ulptx_intr_handler(adapter);
  1360. /* Clear the interrupts just processed for which we are the master. */
  1361. t4_write_reg(adapter, PL_INT_CAUSE, cause & GLBL_INTR_MASK);
  1362. (void) t4_read_reg(adapter, PL_INT_CAUSE); /* flush */
  1363. return 1;
  1364. }
  1365. /**
  1366. * t4_intr_enable - enable interrupts
  1367. * @adapter: the adapter whose interrupts should be enabled
  1368. *
  1369. * Enable PF-specific interrupts for the calling function and the top-level
  1370. * interrupt concentrator for global interrupts. Interrupts are already
  1371. * enabled at each module, here we just enable the roots of the interrupt
  1372. * hierarchies.
  1373. *
  1374. * Note: this function should be called only when the driver manages
  1375. * non PF-specific interrupts from the various HW modules. Only one PCI
  1376. * function at a time should be doing this.
  1377. */
  1378. void t4_intr_enable(struct adapter *adapter)
  1379. {
  1380. u32 pf = SOURCEPF_GET(t4_read_reg(adapter, PL_WHOAMI));
  1381. t4_write_reg(adapter, SGE_INT_ENABLE3, ERR_CPL_EXCEED_IQE_SIZE |
  1382. ERR_INVALID_CIDX_INC | ERR_CPL_OPCODE_0 |
  1383. ERR_DROPPED_DB | ERR_DATA_CPL_ON_HIGH_QID1 |
  1384. ERR_DATA_CPL_ON_HIGH_QID0 | ERR_BAD_DB_PIDX3 |
  1385. ERR_BAD_DB_PIDX2 | ERR_BAD_DB_PIDX1 |
  1386. ERR_BAD_DB_PIDX0 | ERR_ING_CTXT_PRIO |
  1387. ERR_EGR_CTXT_PRIO | INGRESS_SIZE_ERR |
  1388. EGRESS_SIZE_ERR);
  1389. t4_write_reg(adapter, MYPF_REG(PL_PF_INT_ENABLE), PF_INTR_MASK);
  1390. t4_set_reg_field(adapter, PL_INT_MAP0, 0, 1 << pf);
  1391. }
  1392. /**
  1393. * t4_intr_disable - disable interrupts
  1394. * @adapter: the adapter whose interrupts should be disabled
  1395. *
  1396. * Disable interrupts. We only disable the top-level interrupt
  1397. * concentrators. The caller must be a PCI function managing global
  1398. * interrupts.
  1399. */
  1400. void t4_intr_disable(struct adapter *adapter)
  1401. {
  1402. u32 pf = SOURCEPF_GET(t4_read_reg(adapter, PL_WHOAMI));
  1403. t4_write_reg(adapter, MYPF_REG(PL_PF_INT_ENABLE), 0);
  1404. t4_set_reg_field(adapter, PL_INT_MAP0, 1 << pf, 0);
  1405. }
  1406. /**
  1407. * t4_intr_clear - clear all interrupts
  1408. * @adapter: the adapter whose interrupts should be cleared
  1409. *
  1410. * Clears all interrupts. The caller must be a PCI function managing
  1411. * global interrupts.
  1412. */
  1413. void t4_intr_clear(struct adapter *adapter)
  1414. {
  1415. static const unsigned int cause_reg[] = {
  1416. SGE_INT_CAUSE1, SGE_INT_CAUSE2, SGE_INT_CAUSE3,
  1417. PCIE_CORE_UTL_SYSTEM_BUS_AGENT_STATUS,
  1418. PCIE_CORE_UTL_PCI_EXPRESS_PORT_STATUS,
  1419. PCIE_NONFAT_ERR, PCIE_INT_CAUSE,
  1420. MC_INT_CAUSE,
  1421. MA_INT_WRAP_STATUS, MA_PARITY_ERROR_STATUS, MA_INT_CAUSE,
  1422. EDC_INT_CAUSE, EDC_REG(EDC_INT_CAUSE, 1),
  1423. CIM_HOST_INT_CAUSE, CIM_HOST_UPACC_INT_CAUSE,
  1424. MYPF_REG(CIM_PF_HOST_INT_CAUSE),
  1425. TP_INT_CAUSE,
  1426. ULP_RX_INT_CAUSE, ULP_TX_INT_CAUSE,
  1427. PM_RX_INT_CAUSE, PM_TX_INT_CAUSE,
  1428. MPS_RX_PERR_INT_CAUSE,
  1429. CPL_INTR_CAUSE,
  1430. MYPF_REG(PL_PF_INT_CAUSE),
  1431. PL_PL_INT_CAUSE,
  1432. LE_DB_INT_CAUSE,
  1433. };
  1434. unsigned int i;
  1435. for (i = 0; i < ARRAY_SIZE(cause_reg); ++i)
  1436. t4_write_reg(adapter, cause_reg[i], 0xffffffff);
  1437. t4_write_reg(adapter, PL_INT_CAUSE, GLBL_INTR_MASK);
  1438. (void) t4_read_reg(adapter, PL_INT_CAUSE); /* flush */
  1439. }
  1440. /**
  1441. * hash_mac_addr - return the hash value of a MAC address
  1442. * @addr: the 48-bit Ethernet MAC address
  1443. *
  1444. * Hashes a MAC address according to the hash function used by HW inexact
  1445. * (hash) address matching.
  1446. */
  1447. static int hash_mac_addr(const u8 *addr)
  1448. {
  1449. u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
  1450. u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
  1451. a ^= b;
  1452. a ^= (a >> 12);
  1453. a ^= (a >> 6);
  1454. return a & 0x3f;
  1455. }
  1456. /**
  1457. * t4_config_rss_range - configure a portion of the RSS mapping table
  1458. * @adapter: the adapter
  1459. * @mbox: mbox to use for the FW command
  1460. * @viid: virtual interface whose RSS subtable is to be written
  1461. * @start: start entry in the table to write
  1462. * @n: how many table entries to write
  1463. * @rspq: values for the response queue lookup table
  1464. * @nrspq: number of values in @rspq
  1465. *
  1466. * Programs the selected part of the VI's RSS mapping table with the
  1467. * provided values. If @nrspq < @n the supplied values are used repeatedly
  1468. * until the full table range is populated.
  1469. *
  1470. * The caller must ensure the values in @rspq are in the range allowed for
  1471. * @viid.
  1472. */
  1473. int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
  1474. int start, int n, const u16 *rspq, unsigned int nrspq)
  1475. {
  1476. int ret;
  1477. const u16 *rsp = rspq;
  1478. const u16 *rsp_end = rspq + nrspq;
  1479. struct fw_rss_ind_tbl_cmd cmd;
  1480. memset(&cmd, 0, sizeof(cmd));
  1481. cmd.op_to_viid = htonl(FW_CMD_OP(FW_RSS_IND_TBL_CMD) |
  1482. FW_CMD_REQUEST | FW_CMD_WRITE |
  1483. FW_RSS_IND_TBL_CMD_VIID(viid));
  1484. cmd.retval_len16 = htonl(FW_LEN16(cmd));
  1485. /* each fw_rss_ind_tbl_cmd takes up to 32 entries */
  1486. while (n > 0) {
  1487. int nq = min(n, 32);
  1488. __be32 *qp = &cmd.iq0_to_iq2;
  1489. cmd.niqid = htons(nq);
  1490. cmd.startidx = htons(start);
  1491. start += nq;
  1492. n -= nq;
  1493. while (nq > 0) {
  1494. unsigned int v;
  1495. v = FW_RSS_IND_TBL_CMD_IQ0(*rsp);
  1496. if (++rsp >= rsp_end)
  1497. rsp = rspq;
  1498. v |= FW_RSS_IND_TBL_CMD_IQ1(*rsp);
  1499. if (++rsp >= rsp_end)
  1500. rsp = rspq;
  1501. v |= FW_RSS_IND_TBL_CMD_IQ2(*rsp);
  1502. if (++rsp >= rsp_end)
  1503. rsp = rspq;
  1504. *qp++ = htonl(v);
  1505. nq -= 3;
  1506. }
  1507. ret = t4_wr_mbox(adapter, mbox, &cmd, sizeof(cmd), NULL);
  1508. if (ret)
  1509. return ret;
  1510. }
  1511. return 0;
  1512. }
  1513. /**
  1514. * t4_config_glbl_rss - configure the global RSS mode
  1515. * @adapter: the adapter
  1516. * @mbox: mbox to use for the FW command
  1517. * @mode: global RSS mode
  1518. * @flags: mode-specific flags
  1519. *
  1520. * Sets the global RSS mode.
  1521. */
  1522. int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
  1523. unsigned int flags)
  1524. {
  1525. struct fw_rss_glb_config_cmd c;
  1526. memset(&c, 0, sizeof(c));
  1527. c.op_to_write = htonl(FW_CMD_OP(FW_RSS_GLB_CONFIG_CMD) |
  1528. FW_CMD_REQUEST | FW_CMD_WRITE);
  1529. c.retval_len16 = htonl(FW_LEN16(c));
  1530. if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_MANUAL) {
  1531. c.u.manual.mode_pkd = htonl(FW_RSS_GLB_CONFIG_CMD_MODE(mode));
  1532. } else if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
  1533. c.u.basicvirtual.mode_pkd =
  1534. htonl(FW_RSS_GLB_CONFIG_CMD_MODE(mode));
  1535. c.u.basicvirtual.synmapen_to_hashtoeplitz = htonl(flags);
  1536. } else
  1537. return -EINVAL;
  1538. return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
  1539. }
  1540. /* Read an RSS table row */
  1541. static int rd_rss_row(struct adapter *adap, int row, u32 *val)
  1542. {
  1543. t4_write_reg(adap, TP_RSS_LKP_TABLE, 0xfff00000 | row);
  1544. return t4_wait_op_done_val(adap, TP_RSS_LKP_TABLE, LKPTBLROWVLD, 1,
  1545. 5, 0, val);
  1546. }
  1547. /**
  1548. * t4_read_rss - read the contents of the RSS mapping table
  1549. * @adapter: the adapter
  1550. * @map: holds the contents of the RSS mapping table
  1551. *
  1552. * Reads the contents of the RSS hash->queue mapping table.
  1553. */
  1554. int t4_read_rss(struct adapter *adapter, u16 *map)
  1555. {
  1556. u32 val;
  1557. int i, ret;
  1558. for (i = 0; i < RSS_NENTRIES / 2; ++i) {
  1559. ret = rd_rss_row(adapter, i, &val);
  1560. if (ret)
  1561. return ret;
  1562. *map++ = LKPTBLQUEUE0_GET(val);
  1563. *map++ = LKPTBLQUEUE1_GET(val);
  1564. }
  1565. return 0;
  1566. }
  1567. /**
  1568. * t4_tp_get_tcp_stats - read TP's TCP MIB counters
  1569. * @adap: the adapter
  1570. * @v4: holds the TCP/IP counter values
  1571. * @v6: holds the TCP/IPv6 counter values
  1572. *
  1573. * Returns the values of TP's TCP/IP and TCP/IPv6 MIB counters.
  1574. * Either @v4 or @v6 may be %NULL to skip the corresponding stats.
  1575. */
  1576. void t4_tp_get_tcp_stats(struct adapter *adap, struct tp_tcp_stats *v4,
  1577. struct tp_tcp_stats *v6)
  1578. {
  1579. u32 val[TP_MIB_TCP_RXT_SEG_LO - TP_MIB_TCP_OUT_RST + 1];
  1580. #define STAT_IDX(x) ((TP_MIB_TCP_##x) - TP_MIB_TCP_OUT_RST)
  1581. #define STAT(x) val[STAT_IDX(x)]
  1582. #define STAT64(x) (((u64)STAT(x##_HI) << 32) | STAT(x##_LO))
  1583. if (v4) {
  1584. t4_read_indirect(adap, TP_MIB_INDEX, TP_MIB_DATA, val,
  1585. ARRAY_SIZE(val), TP_MIB_TCP_OUT_RST);
  1586. v4->tcpOutRsts = STAT(OUT_RST);
  1587. v4->tcpInSegs = STAT64(IN_SEG);
  1588. v4->tcpOutSegs = STAT64(OUT_SEG);
  1589. v4->tcpRetransSegs = STAT64(RXT_SEG);
  1590. }
  1591. if (v6) {
  1592. t4_read_indirect(adap, TP_MIB_INDEX, TP_MIB_DATA, val,
  1593. ARRAY_SIZE(val), TP_MIB_TCP_V6OUT_RST);
  1594. v6->tcpOutRsts = STAT(OUT_RST);
  1595. v6->tcpInSegs = STAT64(IN_SEG);
  1596. v6->tcpOutSegs = STAT64(OUT_SEG);
  1597. v6->tcpRetransSegs = STAT64(RXT_SEG);
  1598. }
  1599. #undef STAT64
  1600. #undef STAT
  1601. #undef STAT_IDX
  1602. }
  1603. /**
  1604. * t4_tp_get_err_stats - read TP's error MIB counters
  1605. * @adap: the adapter
  1606. * @st: holds the counter values
  1607. *
  1608. * Returns the values of TP's error counters.
  1609. */
  1610. void t4_tp_get_err_stats(struct adapter *adap, struct tp_err_stats *st)
  1611. {
  1612. t4_read_indirect(adap, TP_MIB_INDEX, TP_MIB_DATA, st->macInErrs,
  1613. 12, TP_MIB_MAC_IN_ERR_0);
  1614. t4_read_indirect(adap, TP_MIB_INDEX, TP_MIB_DATA, st->tnlCongDrops,
  1615. 8, TP_MIB_TNL_CNG_DROP_0);
  1616. t4_read_indirect(adap, TP_MIB_INDEX, TP_MIB_DATA, st->tnlTxDrops,
  1617. 4, TP_MIB_TNL_DROP_0);
  1618. t4_read_indirect(adap, TP_MIB_INDEX, TP_MIB_DATA, st->ofldVlanDrops,
  1619. 4, TP_MIB_OFD_VLN_DROP_0);
  1620. t4_read_indirect(adap, TP_MIB_INDEX, TP_MIB_DATA, st->tcp6InErrs,
  1621. 4, TP_MIB_TCP_V6IN_ERR_0);
  1622. t4_read_indirect(adap, TP_MIB_INDEX, TP_MIB_DATA, &st->ofldNoNeigh,
  1623. 2, TP_MIB_OFD_ARP_DROP);
  1624. }
  1625. /**
  1626. * t4_read_mtu_tbl - returns the values in the HW path MTU table
  1627. * @adap: the adapter
  1628. * @mtus: where to store the MTU values
  1629. * @mtu_log: where to store the MTU base-2 log (may be %NULL)
  1630. *
  1631. * Reads the HW path MTU table.
  1632. */
  1633. void t4_read_mtu_tbl(struct adapter *adap, u16 *mtus, u8 *mtu_log)
  1634. {
  1635. u32 v;
  1636. int i;
  1637. for (i = 0; i < NMTUS; ++i) {
  1638. t4_write_reg(adap, TP_MTU_TABLE,
  1639. MTUINDEX(0xff) | MTUVALUE(i));
  1640. v = t4_read_reg(adap, TP_MTU_TABLE);
  1641. mtus[i] = MTUVALUE_GET(v);
  1642. if (mtu_log)
  1643. mtu_log[i] = MTUWIDTH_GET(v);
  1644. }
  1645. }
  1646. /**
  1647. * init_cong_ctrl - initialize congestion control parameters
  1648. * @a: the alpha values for congestion control
  1649. * @b: the beta values for congestion control
  1650. *
  1651. * Initialize the congestion control parameters.
  1652. */
  1653. static void __devinit init_cong_ctrl(unsigned short *a, unsigned short *b)
  1654. {
  1655. a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = a[8] = 1;
  1656. a[9] = 2;
  1657. a[10] = 3;
  1658. a[11] = 4;
  1659. a[12] = 5;
  1660. a[13] = 6;
  1661. a[14] = 7;
  1662. a[15] = 8;
  1663. a[16] = 9;
  1664. a[17] = 10;
  1665. a[18] = 14;
  1666. a[19] = 17;
  1667. a[20] = 21;
  1668. a[21] = 25;
  1669. a[22] = 30;
  1670. a[23] = 35;
  1671. a[24] = 45;
  1672. a[25] = 60;
  1673. a[26] = 80;
  1674. a[27] = 100;
  1675. a[28] = 200;
  1676. a[29] = 300;
  1677. a[30] = 400;
  1678. a[31] = 500;
  1679. b[0] = b[1] = b[2] = b[3] = b[4] = b[5] = b[6] = b[7] = b[8] = 0;
  1680. b[9] = b[10] = 1;
  1681. b[11] = b[12] = 2;
  1682. b[13] = b[14] = b[15] = b[16] = 3;
  1683. b[17] = b[18] = b[19] = b[20] = b[21] = 4;
  1684. b[22] = b[23] = b[24] = b[25] = b[26] = b[27] = 5;
  1685. b[28] = b[29] = 6;
  1686. b[30] = b[31] = 7;
  1687. }
  1688. /* The minimum additive increment value for the congestion control table */
  1689. #define CC_MIN_INCR 2U
  1690. /**
  1691. * t4_load_mtus - write the MTU and congestion control HW tables
  1692. * @adap: the adapter
  1693. * @mtus: the values for the MTU table
  1694. * @alpha: the values for the congestion control alpha parameter
  1695. * @beta: the values for the congestion control beta parameter
  1696. *
  1697. * Write the HW MTU table with the supplied MTUs and the high-speed
  1698. * congestion control table with the supplied alpha, beta, and MTUs.
  1699. * We write the two tables together because the additive increments
  1700. * depend on the MTUs.
  1701. */
  1702. void t4_load_mtus(struct adapter *adap, const unsigned short *mtus,
  1703. const unsigned short *alpha, const unsigned short *beta)
  1704. {
  1705. static const unsigned int avg_pkts[NCCTRL_WIN] = {
  1706. 2, 6, 10, 14, 20, 28, 40, 56, 80, 112, 160, 224, 320, 448, 640,
  1707. 896, 1281, 1792, 2560, 3584, 5120, 7168, 10240, 14336, 20480,
  1708. 28672, 40960, 57344, 81920, 114688, 163840, 229376
  1709. };
  1710. unsigned int i, w;
  1711. for (i = 0; i < NMTUS; ++i) {
  1712. unsigned int mtu = mtus[i];
  1713. unsigned int log2 = fls(mtu);
  1714. if (!(mtu & ((1 << log2) >> 2))) /* round */
  1715. log2--;
  1716. t4_write_reg(adap, TP_MTU_TABLE, MTUINDEX(i) |
  1717. MTUWIDTH(log2) | MTUVALUE(mtu));
  1718. for (w = 0; w < NCCTRL_WIN; ++w) {
  1719. unsigned int inc;
  1720. inc = max(((mtu - 40) * alpha[w]) / avg_pkts[w],
  1721. CC_MIN_INCR);
  1722. t4_write_reg(adap, TP_CCTRL_TABLE, (i << 21) |
  1723. (w << 16) | (beta[w] << 13) | inc);
  1724. }
  1725. }
  1726. }
  1727. /**
  1728. * t4_set_trace_filter - configure one of the tracing filters
  1729. * @adap: the adapter
  1730. * @tp: the desired trace filter parameters
  1731. * @idx: which filter to configure
  1732. * @enable: whether to enable or disable the filter
  1733. *
  1734. * Configures one of the tracing filters available in HW. If @enable is
  1735. * %0 @tp is not examined and may be %NULL.
  1736. */
  1737. int t4_set_trace_filter(struct adapter *adap, const struct trace_params *tp,
  1738. int idx, int enable)
  1739. {
  1740. int i, ofst = idx * 4;
  1741. u32 data_reg, mask_reg, cfg;
  1742. u32 multitrc = TRCMULTIFILTER;
  1743. if (!enable) {
  1744. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A + ofst, 0);
  1745. goto out;
  1746. }
  1747. if (tp->port > 11 || tp->invert > 1 || tp->skip_len > 0x1f ||
  1748. tp->skip_ofst > 0x1f || tp->min_len > 0x1ff ||
  1749. tp->snap_len > 9600 || (idx && tp->snap_len > 256))
  1750. return -EINVAL;
  1751. if (tp->snap_len > 256) { /* must be tracer 0 */
  1752. if ((t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A + 4) |
  1753. t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A + 8) |
  1754. t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A + 12)) & TFEN)
  1755. return -EINVAL; /* other tracers are enabled */
  1756. multitrc = 0;
  1757. } else if (idx) {
  1758. i = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_B);
  1759. if (TFCAPTUREMAX_GET(i) > 256 &&
  1760. (t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A) & TFEN))
  1761. return -EINVAL;
  1762. }
  1763. /* stop the tracer we'll be changing */
  1764. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A + ofst, 0);
  1765. /* disable tracing globally if running in the wrong single/multi mode */
  1766. cfg = t4_read_reg(adap, MPS_TRC_CFG);
  1767. if ((cfg & TRCEN) && multitrc != (cfg & TRCMULTIFILTER)) {
  1768. t4_write_reg(adap, MPS_TRC_CFG, cfg ^ TRCEN);
  1769. t4_read_reg(adap, MPS_TRC_CFG); /* flush */
  1770. msleep(1);
  1771. if (!(t4_read_reg(adap, MPS_TRC_CFG) & TRCFIFOEMPTY))
  1772. return -ETIMEDOUT;
  1773. }
  1774. /*
  1775. * At this point either the tracing is enabled and in the right mode or
  1776. * disabled.
  1777. */
  1778. idx *= (MPS_TRC_FILTER1_MATCH - MPS_TRC_FILTER0_MATCH);
  1779. data_reg = MPS_TRC_FILTER0_MATCH + idx;
  1780. mask_reg = MPS_TRC_FILTER0_DONT_CARE + idx;
  1781. for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
  1782. t4_write_reg(adap, data_reg, tp->data[i]);
  1783. t4_write_reg(adap, mask_reg, ~tp->mask[i]);
  1784. }
  1785. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_B + ofst,
  1786. TFCAPTUREMAX(tp->snap_len) |
  1787. TFMINPKTSIZE(tp->min_len));
  1788. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A + ofst,
  1789. TFOFFSET(tp->skip_ofst) | TFLENGTH(tp->skip_len) |
  1790. TFPORT(tp->port) | TFEN |
  1791. (tp->invert ? TFINVERTMATCH : 0));
  1792. cfg &= ~TRCMULTIFILTER;
  1793. t4_write_reg(adap, MPS_TRC_CFG, cfg | TRCEN | multitrc);
  1794. out: t4_read_reg(adap, MPS_TRC_CFG); /* flush */
  1795. return 0;
  1796. }
  1797. /**
  1798. * t4_get_trace_filter - query one of the tracing filters
  1799. * @adap: the adapter
  1800. * @tp: the current trace filter parameters
  1801. * @idx: which trace filter to query
  1802. * @enabled: non-zero if the filter is enabled
  1803. *
  1804. * Returns the current settings of one of the HW tracing filters.
  1805. */
  1806. void t4_get_trace_filter(struct adapter *adap, struct trace_params *tp, int idx,
  1807. int *enabled)
  1808. {
  1809. u32 ctla, ctlb;
  1810. int i, ofst = idx * 4;
  1811. u32 data_reg, mask_reg;
  1812. ctla = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A + ofst);
  1813. ctlb = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_B + ofst);
  1814. *enabled = !!(ctla & TFEN);
  1815. tp->snap_len = TFCAPTUREMAX_GET(ctlb);
  1816. tp->min_len = TFMINPKTSIZE_GET(ctlb);
  1817. tp->skip_ofst = TFOFFSET_GET(ctla);
  1818. tp->skip_len = TFLENGTH_GET(ctla);
  1819. tp->invert = !!(ctla & TFINVERTMATCH);
  1820. tp->port = TFPORT_GET(ctla);
  1821. ofst = (MPS_TRC_FILTER1_MATCH - MPS_TRC_FILTER0_MATCH) * idx;
  1822. data_reg = MPS_TRC_FILTER0_MATCH + ofst;
  1823. mask_reg = MPS_TRC_FILTER0_DONT_CARE + ofst;
  1824. for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
  1825. tp->mask[i] = ~t4_read_reg(adap, mask_reg);
  1826. tp->data[i] = t4_read_reg(adap, data_reg) & tp->mask[i];
  1827. }
  1828. }
  1829. /**
  1830. * get_mps_bg_map - return the buffer groups associated with a port
  1831. * @adap: the adapter
  1832. * @idx: the port index
  1833. *
  1834. * Returns a bitmap indicating which MPS buffer groups are associated
  1835. * with the given port. Bit i is set if buffer group i is used by the
  1836. * port.
  1837. */
  1838. static unsigned int get_mps_bg_map(struct adapter *adap, int idx)
  1839. {
  1840. u32 n = NUMPORTS_GET(t4_read_reg(adap, MPS_CMN_CTL));
  1841. if (n == 0)
  1842. return idx == 0 ? 0xf : 0;
  1843. if (n == 1)
  1844. return idx < 2 ? (3 << (2 * idx)) : 0;
  1845. return 1 << idx;
  1846. }
  1847. /**
  1848. * t4_get_port_stats - collect port statistics
  1849. * @adap: the adapter
  1850. * @idx: the port index
  1851. * @p: the stats structure to fill
  1852. *
  1853. * Collect statistics related to the given port from HW.
  1854. */
  1855. void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p)
  1856. {
  1857. u32 bgmap = get_mps_bg_map(adap, idx);
  1858. #define GET_STAT(name) \
  1859. t4_read_reg64(adap, PORT_REG(idx, MPS_PORT_STAT_##name##_L))
  1860. #define GET_STAT_COM(name) t4_read_reg64(adap, MPS_STAT_##name##_L)
  1861. p->tx_octets = GET_STAT(TX_PORT_BYTES);
  1862. p->tx_frames = GET_STAT(TX_PORT_FRAMES);
  1863. p->tx_bcast_frames = GET_STAT(TX_PORT_BCAST);
  1864. p->tx_mcast_frames = GET_STAT(TX_PORT_MCAST);
  1865. p->tx_ucast_frames = GET_STAT(TX_PORT_UCAST);
  1866. p->tx_error_frames = GET_STAT(TX_PORT_ERROR);
  1867. p->tx_frames_64 = GET_STAT(TX_PORT_64B);
  1868. p->tx_frames_65_127 = GET_STAT(TX_PORT_65B_127B);
  1869. p->tx_frames_128_255 = GET_STAT(TX_PORT_128B_255B);
  1870. p->tx_frames_256_511 = GET_STAT(TX_PORT_256B_511B);
  1871. p->tx_frames_512_1023 = GET_STAT(TX_PORT_512B_1023B);
  1872. p->tx_frames_1024_1518 = GET_STAT(TX_PORT_1024B_1518B);
  1873. p->tx_frames_1519_max = GET_STAT(TX_PORT_1519B_MAX);
  1874. p->tx_drop = GET_STAT(TX_PORT_DROP);
  1875. p->tx_pause = GET_STAT(TX_PORT_PAUSE);
  1876. p->tx_ppp0 = GET_STAT(TX_PORT_PPP0);
  1877. p->tx_ppp1 = GET_STAT(TX_PORT_PPP1);
  1878. p->tx_ppp2 = GET_STAT(TX_PORT_PPP2);
  1879. p->tx_ppp3 = GET_STAT(TX_PORT_PPP3);
  1880. p->tx_ppp4 = GET_STAT(TX_PORT_PPP4);
  1881. p->tx_ppp5 = GET_STAT(TX_PORT_PPP5);
  1882. p->tx_ppp6 = GET_STAT(TX_PORT_PPP6);
  1883. p->tx_ppp7 = GET_STAT(TX_PORT_PPP7);
  1884. p->rx_octets = GET_STAT(RX_PORT_BYTES);
  1885. p->rx_frames = GET_STAT(RX_PORT_FRAMES);
  1886. p->rx_bcast_frames = GET_STAT(RX_PORT_BCAST);
  1887. p->rx_mcast_frames = GET_STAT(RX_PORT_MCAST);
  1888. p->rx_ucast_frames = GET_STAT(RX_PORT_UCAST);
  1889. p->rx_too_long = GET_STAT(RX_PORT_MTU_ERROR);
  1890. p->rx_jabber = GET_STAT(RX_PORT_MTU_CRC_ERROR);
  1891. p->rx_fcs_err = GET_STAT(RX_PORT_CRC_ERROR);
  1892. p->rx_len_err = GET_STAT(RX_PORT_LEN_ERROR);
  1893. p->rx_symbol_err = GET_STAT(RX_PORT_SYM_ERROR);
  1894. p->rx_runt = GET_STAT(RX_PORT_LESS_64B);
  1895. p->rx_frames_64 = GET_STAT(RX_PORT_64B);
  1896. p->rx_frames_65_127 = GET_STAT(RX_PORT_65B_127B);
  1897. p->rx_frames_128_255 = GET_STAT(RX_PORT_128B_255B);
  1898. p->rx_frames_256_511 = GET_STAT(RX_PORT_256B_511B);
  1899. p->rx_frames_512_1023 = GET_STAT(RX_PORT_512B_1023B);
  1900. p->rx_frames_1024_1518 = GET_STAT(RX_PORT_1024B_1518B);
  1901. p->rx_frames_1519_max = GET_STAT(RX_PORT_1519B_MAX);
  1902. p->rx_pause = GET_STAT(RX_PORT_PAUSE);
  1903. p->rx_ppp0 = GET_STAT(RX_PORT_PPP0);
  1904. p->rx_ppp1 = GET_STAT(RX_PORT_PPP1);
  1905. p->rx_ppp2 = GET_STAT(RX_PORT_PPP2);
  1906. p->rx_ppp3 = GET_STAT(RX_PORT_PPP3);
  1907. p->rx_ppp4 = GET_STAT(RX_PORT_PPP4);
  1908. p->rx_ppp5 = GET_STAT(RX_PORT_PPP5);
  1909. p->rx_ppp6 = GET_STAT(RX_PORT_PPP6);
  1910. p->rx_ppp7 = GET_STAT(RX_PORT_PPP7);
  1911. p->rx_ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_DROP_FRAME) : 0;
  1912. p->rx_ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_DROP_FRAME) : 0;
  1913. p->rx_ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_DROP_FRAME) : 0;
  1914. p->rx_ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_DROP_FRAME) : 0;
  1915. p->rx_trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_TRUNC_FRAME) : 0;
  1916. p->rx_trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_TRUNC_FRAME) : 0;
  1917. p->rx_trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_TRUNC_FRAME) : 0;
  1918. p->rx_trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_TRUNC_FRAME) : 0;
  1919. #undef GET_STAT
  1920. #undef GET_STAT_COM
  1921. }
  1922. /**
  1923. * t4_get_lb_stats - collect loopback port statistics
  1924. * @adap: the adapter
  1925. * @idx: the loopback port index
  1926. * @p: the stats structure to fill
  1927. *
  1928. * Return HW statistics for the given loopback port.
  1929. */
  1930. void t4_get_lb_stats(struct adapter *adap, int idx, struct lb_port_stats *p)
  1931. {
  1932. u32 bgmap = get_mps_bg_map(adap, idx);
  1933. #define GET_STAT(name) \
  1934. t4_read_reg64(adap, PORT_REG(idx, MPS_PORT_STAT_LB_PORT_##name##_L))
  1935. #define GET_STAT_COM(name) t4_read_reg64(adap, MPS_STAT_##name##_L)
  1936. p->octets = GET_STAT(BYTES);
  1937. p->frames = GET_STAT(FRAMES);
  1938. p->bcast_frames = GET_STAT(BCAST);
  1939. p->mcast_frames = GET_STAT(MCAST);
  1940. p->ucast_frames = GET_STAT(UCAST);
  1941. p->error_frames = GET_STAT(ERROR);
  1942. p->frames_64 = GET_STAT(64B);
  1943. p->frames_65_127 = GET_STAT(65B_127B);
  1944. p->frames_128_255 = GET_STAT(128B_255B);
  1945. p->frames_256_511 = GET_STAT(256B_511B);
  1946. p->frames_512_1023 = GET_STAT(512B_1023B);
  1947. p->frames_1024_1518 = GET_STAT(1024B_1518B);
  1948. p->frames_1519_max = GET_STAT(1519B_MAX);
  1949. p->drop = t4_read_reg(adap, PORT_REG(idx,
  1950. MPS_PORT_STAT_LB_PORT_DROP_FRAMES));
  1951. p->ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_LB_DROP_FRAME) : 0;
  1952. p->ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_LB_DROP_FRAME) : 0;
  1953. p->ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_LB_DROP_FRAME) : 0;
  1954. p->ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_LB_DROP_FRAME) : 0;
  1955. p->trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_LB_TRUNC_FRAME) : 0;
  1956. p->trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_LB_TRUNC_FRAME) : 0;
  1957. p->trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_LB_TRUNC_FRAME) : 0;
  1958. p->trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_LB_TRUNC_FRAME) : 0;
  1959. #undef GET_STAT
  1960. #undef GET_STAT_COM
  1961. }
  1962. /**
  1963. * t4_wol_magic_enable - enable/disable magic packet WoL
  1964. * @adap: the adapter
  1965. * @port: the physical port index
  1966. * @addr: MAC address expected in magic packets, %NULL to disable
  1967. *
  1968. * Enables/disables magic packet wake-on-LAN for the selected port.
  1969. */
  1970. void t4_wol_magic_enable(struct adapter *adap, unsigned int port,
  1971. const u8 *addr)
  1972. {
  1973. if (addr) {
  1974. t4_write_reg(adap, PORT_REG(port, XGMAC_PORT_MAGIC_MACID_LO),
  1975. (addr[2] << 24) | (addr[3] << 16) |
  1976. (addr[4] << 8) | addr[5]);
  1977. t4_write_reg(adap, PORT_REG(port, XGMAC_PORT_MAGIC_MACID_HI),
  1978. (addr[0] << 8) | addr[1]);
  1979. }
  1980. t4_set_reg_field(adap, PORT_REG(port, XGMAC_PORT_CFG2), MAGICEN,
  1981. addr ? MAGICEN : 0);
  1982. }
  1983. /**
  1984. * t4_wol_pat_enable - enable/disable pattern-based WoL
  1985. * @adap: the adapter
  1986. * @port: the physical port index
  1987. * @map: bitmap of which HW pattern filters to set
  1988. * @mask0: byte mask for bytes 0-63 of a packet
  1989. * @mask1: byte mask for bytes 64-127 of a packet
  1990. * @crc: Ethernet CRC for selected bytes
  1991. * @enable: enable/disable switch
  1992. *
  1993. * Sets the pattern filters indicated in @map to mask out the bytes
  1994. * specified in @mask0/@mask1 in received packets and compare the CRC of
  1995. * the resulting packet against @crc. If @enable is %true pattern-based
  1996. * WoL is enabled, otherwise disabled.
  1997. */
  1998. int t4_wol_pat_enable(struct adapter *adap, unsigned int port, unsigned int map,
  1999. u64 mask0, u64 mask1, unsigned int crc, bool enable)
  2000. {
  2001. int i;
  2002. if (!enable) {
  2003. t4_set_reg_field(adap, PORT_REG(port, XGMAC_PORT_CFG2),
  2004. PATEN, 0);
  2005. return 0;
  2006. }
  2007. if (map > 0xff)
  2008. return -EINVAL;
  2009. #define EPIO_REG(name) PORT_REG(port, XGMAC_PORT_EPIO_##name)
  2010. t4_write_reg(adap, EPIO_REG(DATA1), mask0 >> 32);
  2011. t4_write_reg(adap, EPIO_REG(DATA2), mask1);
  2012. t4_write_reg(adap, EPIO_REG(DATA3), mask1 >> 32);
  2013. for (i = 0; i < NWOL_PAT; i++, map >>= 1) {
  2014. if (!(map & 1))
  2015. continue;
  2016. /* write byte masks */
  2017. t4_write_reg(adap, EPIO_REG(DATA0), mask0);
  2018. t4_write_reg(adap, EPIO_REG(OP), ADDRESS(i) | EPIOWR);
  2019. t4_read_reg(adap, EPIO_REG(OP)); /* flush */
  2020. if (t4_read_reg(adap, EPIO_REG(OP)) & BUSY)
  2021. return -ETIMEDOUT;
  2022. /* write CRC */
  2023. t4_write_reg(adap, EPIO_REG(DATA0), crc);
  2024. t4_write_reg(adap, EPIO_REG(OP), ADDRESS(i + 32) | EPIOWR);
  2025. t4_read_reg(adap, EPIO_REG(OP)); /* flush */
  2026. if (t4_read_reg(adap, EPIO_REG(OP)) & BUSY)
  2027. return -ETIMEDOUT;
  2028. }
  2029. #undef EPIO_REG
  2030. t4_set_reg_field(adap, PORT_REG(port, XGMAC_PORT_CFG2), 0, PATEN);
  2031. return 0;
  2032. }
  2033. #define INIT_CMD(var, cmd, rd_wr) do { \
  2034. (var).op_to_write = htonl(FW_CMD_OP(FW_##cmd##_CMD) | \
  2035. FW_CMD_REQUEST | FW_CMD_##rd_wr); \
  2036. (var).retval_len16 = htonl(FW_LEN16(var)); \
  2037. } while (0)
  2038. /**
  2039. * t4_mdio_rd - read a PHY register through MDIO
  2040. * @adap: the adapter
  2041. * @mbox: mailbox to use for the FW command
  2042. * @phy_addr: the PHY address
  2043. * @mmd: the PHY MMD to access (0 for clause 22 PHYs)
  2044. * @reg: the register to read
  2045. * @valp: where to store the value
  2046. *
  2047. * Issues a FW command through the given mailbox to read a PHY register.
  2048. */
  2049. int t4_mdio_rd(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  2050. unsigned int mmd, unsigned int reg, u16 *valp)
  2051. {
  2052. int ret;
  2053. struct fw_ldst_cmd c;
  2054. memset(&c, 0, sizeof(c));
  2055. c.op_to_addrspace = htonl(FW_CMD_OP(FW_LDST_CMD) | FW_CMD_REQUEST |
  2056. FW_CMD_READ | FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MDIO));
  2057. c.cycles_to_len16 = htonl(FW_LEN16(c));
  2058. c.u.mdio.paddr_mmd = htons(FW_LDST_CMD_PADDR(phy_addr) |
  2059. FW_LDST_CMD_MMD(mmd));
  2060. c.u.mdio.raddr = htons(reg);
  2061. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  2062. if (ret == 0)
  2063. *valp = ntohs(c.u.mdio.rval);
  2064. return ret;
  2065. }
  2066. /**
  2067. * t4_mdio_wr - write a PHY register through MDIO
  2068. * @adap: the adapter
  2069. * @mbox: mailbox to use for the FW command
  2070. * @phy_addr: the PHY address
  2071. * @mmd: the PHY MMD to access (0 for clause 22 PHYs)
  2072. * @reg: the register to write
  2073. * @valp: value to write
  2074. *
  2075. * Issues a FW command through the given mailbox to write a PHY register.
  2076. */
  2077. int t4_mdio_wr(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  2078. unsigned int mmd, unsigned int reg, u16 val)
  2079. {
  2080. struct fw_ldst_cmd c;
  2081. memset(&c, 0, sizeof(c));
  2082. c.op_to_addrspace = htonl(FW_CMD_OP(FW_LDST_CMD) | FW_CMD_REQUEST |
  2083. FW_CMD_WRITE | FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MDIO));
  2084. c.cycles_to_len16 = htonl(FW_LEN16(c));
  2085. c.u.mdio.paddr_mmd = htons(FW_LDST_CMD_PADDR(phy_addr) |
  2086. FW_LDST_CMD_MMD(mmd));
  2087. c.u.mdio.raddr = htons(reg);
  2088. c.u.mdio.rval = htons(val);
  2089. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2090. }
  2091. /**
  2092. * t4_fw_hello - establish communication with FW
  2093. * @adap: the adapter
  2094. * @mbox: mailbox to use for the FW command
  2095. * @evt_mbox: mailbox to receive async FW events
  2096. * @master: specifies the caller's willingness to be the device master
  2097. * @state: returns the current device state
  2098. *
  2099. * Issues a command to establish communication with FW.
  2100. */
  2101. int t4_fw_hello(struct adapter *adap, unsigned int mbox, unsigned int evt_mbox,
  2102. enum dev_master master, enum dev_state *state)
  2103. {
  2104. int ret;
  2105. struct fw_hello_cmd c;
  2106. INIT_CMD(c, HELLO, WRITE);
  2107. c.err_to_mbasyncnot = htonl(
  2108. FW_HELLO_CMD_MASTERDIS(master == MASTER_CANT) |
  2109. FW_HELLO_CMD_MASTERFORCE(master == MASTER_MUST) |
  2110. FW_HELLO_CMD_MBMASTER(master == MASTER_MUST ? mbox : 0xff) |
  2111. FW_HELLO_CMD_MBASYNCNOT(evt_mbox));
  2112. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  2113. if (ret == 0 && state) {
  2114. u32 v = ntohl(c.err_to_mbasyncnot);
  2115. if (v & FW_HELLO_CMD_INIT)
  2116. *state = DEV_STATE_INIT;
  2117. else if (v & FW_HELLO_CMD_ERR)
  2118. *state = DEV_STATE_ERR;
  2119. else
  2120. *state = DEV_STATE_UNINIT;
  2121. }
  2122. return ret;
  2123. }
  2124. /**
  2125. * t4_fw_bye - end communication with FW
  2126. * @adap: the adapter
  2127. * @mbox: mailbox to use for the FW command
  2128. *
  2129. * Issues a command to terminate communication with FW.
  2130. */
  2131. int t4_fw_bye(struct adapter *adap, unsigned int mbox)
  2132. {
  2133. struct fw_bye_cmd c;
  2134. INIT_CMD(c, BYE, WRITE);
  2135. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2136. }
  2137. /**
  2138. * t4_init_cmd - ask FW to initialize the device
  2139. * @adap: the adapter
  2140. * @mbox: mailbox to use for the FW command
  2141. *
  2142. * Issues a command to FW to partially initialize the device. This
  2143. * performs initialization that generally doesn't depend on user input.
  2144. */
  2145. int t4_early_init(struct adapter *adap, unsigned int mbox)
  2146. {
  2147. struct fw_initialize_cmd c;
  2148. INIT_CMD(c, INITIALIZE, WRITE);
  2149. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2150. }
  2151. /**
  2152. * t4_fw_reset - issue a reset to FW
  2153. * @adap: the adapter
  2154. * @mbox: mailbox to use for the FW command
  2155. * @reset: specifies the type of reset to perform
  2156. *
  2157. * Issues a reset command of the specified type to FW.
  2158. */
  2159. int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset)
  2160. {
  2161. struct fw_reset_cmd c;
  2162. INIT_CMD(c, RESET, WRITE);
  2163. c.val = htonl(reset);
  2164. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2165. }
  2166. /**
  2167. * t4_query_params - query FW or device parameters
  2168. * @adap: the adapter
  2169. * @mbox: mailbox to use for the FW command
  2170. * @pf: the PF
  2171. * @vf: the VF
  2172. * @nparams: the number of parameters
  2173. * @params: the parameter names
  2174. * @val: the parameter values
  2175. *
  2176. * Reads the value of FW or device parameters. Up to 7 parameters can be
  2177. * queried at once.
  2178. */
  2179. int t4_query_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  2180. unsigned int vf, unsigned int nparams, const u32 *params,
  2181. u32 *val)
  2182. {
  2183. int i, ret;
  2184. struct fw_params_cmd c;
  2185. __be32 *p = &c.param[0].mnem;
  2186. if (nparams > 7)
  2187. return -EINVAL;
  2188. memset(&c, 0, sizeof(c));
  2189. c.op_to_vfn = htonl(FW_CMD_OP(FW_PARAMS_CMD) | FW_CMD_REQUEST |
  2190. FW_CMD_READ | FW_PARAMS_CMD_PFN(pf) |
  2191. FW_PARAMS_CMD_VFN(vf));
  2192. c.retval_len16 = htonl(FW_LEN16(c));
  2193. for (i = 0; i < nparams; i++, p += 2)
  2194. *p = htonl(*params++);
  2195. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  2196. if (ret == 0)
  2197. for (i = 0, p = &c.param[0].val; i < nparams; i++, p += 2)
  2198. *val++ = ntohl(*p);
  2199. return ret;
  2200. }
  2201. /**
  2202. * t4_set_params - sets FW or device parameters
  2203. * @adap: the adapter
  2204. * @mbox: mailbox to use for the FW command
  2205. * @pf: the PF
  2206. * @vf: the VF
  2207. * @nparams: the number of parameters
  2208. * @params: the parameter names
  2209. * @val: the parameter values
  2210. *
  2211. * Sets the value of FW or device parameters. Up to 7 parameters can be
  2212. * specified at once.
  2213. */
  2214. int t4_set_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  2215. unsigned int vf, unsigned int nparams, const u32 *params,
  2216. const u32 *val)
  2217. {
  2218. struct fw_params_cmd c;
  2219. __be32 *p = &c.param[0].mnem;
  2220. if (nparams > 7)
  2221. return -EINVAL;
  2222. memset(&c, 0, sizeof(c));
  2223. c.op_to_vfn = htonl(FW_CMD_OP(FW_PARAMS_CMD) | FW_CMD_REQUEST |
  2224. FW_CMD_WRITE | FW_PARAMS_CMD_PFN(pf) |
  2225. FW_PARAMS_CMD_VFN(vf));
  2226. c.retval_len16 = htonl(FW_LEN16(c));
  2227. while (nparams--) {
  2228. *p++ = htonl(*params++);
  2229. *p++ = htonl(*val++);
  2230. }
  2231. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2232. }
  2233. /**
  2234. * t4_cfg_pfvf - configure PF/VF resource limits
  2235. * @adap: the adapter
  2236. * @mbox: mailbox to use for the FW command
  2237. * @pf: the PF being configured
  2238. * @vf: the VF being configured
  2239. * @txq: the max number of egress queues
  2240. * @txq_eth_ctrl: the max number of egress Ethernet or control queues
  2241. * @rxqi: the max number of interrupt-capable ingress queues
  2242. * @rxq: the max number of interruptless ingress queues
  2243. * @tc: the PCI traffic class
  2244. * @vi: the max number of virtual interfaces
  2245. * @cmask: the channel access rights mask for the PF/VF
  2246. * @pmask: the port access rights mask for the PF/VF
  2247. * @nexact: the maximum number of exact MPS filters
  2248. * @rcaps: read capabilities
  2249. * @wxcaps: write/execute capabilities
  2250. *
  2251. * Configures resource limits and capabilities for a physical or virtual
  2252. * function.
  2253. */
  2254. int t4_cfg_pfvf(struct adapter *adap, unsigned int mbox, unsigned int pf,
  2255. unsigned int vf, unsigned int txq, unsigned int txq_eth_ctrl,
  2256. unsigned int rxqi, unsigned int rxq, unsigned int tc,
  2257. unsigned int vi, unsigned int cmask, unsigned int pmask,
  2258. unsigned int nexact, unsigned int rcaps, unsigned int wxcaps)
  2259. {
  2260. struct fw_pfvf_cmd c;
  2261. memset(&c, 0, sizeof(c));
  2262. c.op_to_vfn = htonl(FW_CMD_OP(FW_PFVF_CMD) | FW_CMD_REQUEST |
  2263. FW_CMD_WRITE | FW_PFVF_CMD_PFN(pf) |
  2264. FW_PFVF_CMD_VFN(vf));
  2265. c.retval_len16 = htonl(FW_LEN16(c));
  2266. c.niqflint_niq = htonl(FW_PFVF_CMD_NIQFLINT(rxqi) |
  2267. FW_PFVF_CMD_NIQ(rxq));
  2268. c.cmask_to_neq = htonl(FW_PFVF_CMD_CMASK(cmask) |
  2269. FW_PFVF_CMD_PMASK(pmask) |
  2270. FW_PFVF_CMD_NEQ(txq));
  2271. c.tc_to_nexactf = htonl(FW_PFVF_CMD_TC(tc) | FW_PFVF_CMD_NVI(vi) |
  2272. FW_PFVF_CMD_NEXACTF(nexact));
  2273. c.r_caps_to_nethctrl = htonl(FW_PFVF_CMD_R_CAPS(rcaps) |
  2274. FW_PFVF_CMD_WX_CAPS(wxcaps) |
  2275. FW_PFVF_CMD_NETHCTRL(txq_eth_ctrl));
  2276. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2277. }
  2278. /**
  2279. * t4_alloc_vi - allocate a virtual interface
  2280. * @adap: the adapter
  2281. * @mbox: mailbox to use for the FW command
  2282. * @port: physical port associated with the VI
  2283. * @pf: the PF owning the VI
  2284. * @vf: the VF owning the VI
  2285. * @nmac: number of MAC addresses needed (1 to 5)
  2286. * @mac: the MAC addresses of the VI
  2287. * @rss_size: size of RSS table slice associated with this VI
  2288. *
  2289. * Allocates a virtual interface for the given physical port. If @mac is
  2290. * not %NULL it contains the MAC addresses of the VI as assigned by FW.
  2291. * @mac should be large enough to hold @nmac Ethernet addresses, they are
  2292. * stored consecutively so the space needed is @nmac * 6 bytes.
  2293. * Returns a negative error number or the non-negative VI id.
  2294. */
  2295. int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
  2296. unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
  2297. unsigned int *rss_size)
  2298. {
  2299. int ret;
  2300. struct fw_vi_cmd c;
  2301. memset(&c, 0, sizeof(c));
  2302. c.op_to_vfn = htonl(FW_CMD_OP(FW_VI_CMD) | FW_CMD_REQUEST |
  2303. FW_CMD_WRITE | FW_CMD_EXEC |
  2304. FW_VI_CMD_PFN(pf) | FW_VI_CMD_VFN(vf));
  2305. c.alloc_to_len16 = htonl(FW_VI_CMD_ALLOC | FW_LEN16(c));
  2306. c.portid_pkd = FW_VI_CMD_PORTID(port);
  2307. c.nmac = nmac - 1;
  2308. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  2309. if (ret)
  2310. return ret;
  2311. if (mac) {
  2312. memcpy(mac, c.mac, sizeof(c.mac));
  2313. switch (nmac) {
  2314. case 5:
  2315. memcpy(mac + 24, c.nmac3, sizeof(c.nmac3));
  2316. case 4:
  2317. memcpy(mac + 18, c.nmac2, sizeof(c.nmac2));
  2318. case 3:
  2319. memcpy(mac + 12, c.nmac1, sizeof(c.nmac1));
  2320. case 2:
  2321. memcpy(mac + 6, c.nmac0, sizeof(c.nmac0));
  2322. }
  2323. }
  2324. if (rss_size)
  2325. *rss_size = FW_VI_CMD_RSSSIZE_GET(ntohs(c.rsssize_pkd));
  2326. return ntohs(c.viid_pkd);
  2327. }
  2328. /**
  2329. * t4_free_vi - free a virtual interface
  2330. * @adap: the adapter
  2331. * @mbox: mailbox to use for the FW command
  2332. * @pf: the PF owning the VI
  2333. * @vf: the VF owning the VI
  2334. * @viid: virtual interface identifiler
  2335. *
  2336. * Free a previously allocated virtual interface.
  2337. */
  2338. int t4_free_vi(struct adapter *adap, unsigned int mbox, unsigned int pf,
  2339. unsigned int vf, unsigned int viid)
  2340. {
  2341. struct fw_vi_cmd c;
  2342. memset(&c, 0, sizeof(c));
  2343. c.op_to_vfn = htonl(FW_CMD_OP(FW_VI_CMD) | FW_CMD_REQUEST |
  2344. FW_CMD_EXEC | FW_VI_CMD_PFN(pf) |
  2345. FW_VI_CMD_VFN(vf));
  2346. c.alloc_to_len16 = htonl(FW_VI_CMD_FREE | FW_LEN16(c));
  2347. c.viid_pkd = htons(FW_VI_CMD_VIID(viid));
  2348. return t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  2349. }
  2350. /**
  2351. * t4_set_rxmode - set Rx properties of a virtual interface
  2352. * @adap: the adapter
  2353. * @mbox: mailbox to use for the FW command
  2354. * @viid: the VI id
  2355. * @mtu: the new MTU or -1
  2356. * @promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change
  2357. * @all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change
  2358. * @bcast: 1 to enable broadcast Rx, 0 to disable it, -1 no change
  2359. * @sleep_ok: if true we may sleep while awaiting command completion
  2360. *
  2361. * Sets Rx properties of a virtual interface.
  2362. */
  2363. int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
  2364. int mtu, int promisc, int all_multi, int bcast, bool sleep_ok)
  2365. {
  2366. struct fw_vi_rxmode_cmd c;
  2367. /* convert to FW values */
  2368. if (mtu < 0)
  2369. mtu = FW_RXMODE_MTU_NO_CHG;
  2370. if (promisc < 0)
  2371. promisc = FW_VI_RXMODE_CMD_PROMISCEN_MASK;
  2372. if (all_multi < 0)
  2373. all_multi = FW_VI_RXMODE_CMD_ALLMULTIEN_MASK;
  2374. if (bcast < 0)
  2375. bcast = FW_VI_RXMODE_CMD_BROADCASTEN_MASK;
  2376. memset(&c, 0, sizeof(c));
  2377. c.op_to_viid = htonl(FW_CMD_OP(FW_VI_RXMODE_CMD) | FW_CMD_REQUEST |
  2378. FW_CMD_WRITE | FW_VI_RXMODE_CMD_VIID(viid));
  2379. c.retval_len16 = htonl(FW_LEN16(c));
  2380. c.mtu_to_broadcasten = htonl(FW_VI_RXMODE_CMD_MTU(mtu) |
  2381. FW_VI_RXMODE_CMD_PROMISCEN(promisc) |
  2382. FW_VI_RXMODE_CMD_ALLMULTIEN(all_multi) |
  2383. FW_VI_RXMODE_CMD_BROADCASTEN(bcast));
  2384. return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
  2385. }
  2386. /**
  2387. * t4_alloc_mac_filt - allocates exact-match filters for MAC addresses
  2388. * @adap: the adapter
  2389. * @mbox: mailbox to use for the FW command
  2390. * @viid: the VI id
  2391. * @free: if true any existing filters for this VI id are first removed
  2392. * @naddr: the number of MAC addresses to allocate filters for (up to 7)
  2393. * @addr: the MAC address(es)
  2394. * @idx: where to store the index of each allocated filter
  2395. * @hash: pointer to hash address filter bitmap
  2396. * @sleep_ok: call is allowed to sleep
  2397. *
  2398. * Allocates an exact-match filter for each of the supplied addresses and
  2399. * sets it to the corresponding address. If @idx is not %NULL it should
  2400. * have at least @naddr entries, each of which will be set to the index of
  2401. * the filter allocated for the corresponding MAC address. If a filter
  2402. * could not be allocated for an address its index is set to 0xffff.
  2403. * If @hash is not %NULL addresses that fail to allocate an exact filter
  2404. * are hashed and update the hash filter bitmap pointed at by @hash.
  2405. *
  2406. * Returns a negative error number or the number of filters allocated.
  2407. */
  2408. int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
  2409. unsigned int viid, bool free, unsigned int naddr,
  2410. const u8 **addr, u16 *idx, u64 *hash, bool sleep_ok)
  2411. {
  2412. int i, ret;
  2413. struct fw_vi_mac_cmd c;
  2414. struct fw_vi_mac_exact *p;
  2415. if (naddr > 7)
  2416. return -EINVAL;
  2417. memset(&c, 0, sizeof(c));
  2418. c.op_to_viid = htonl(FW_CMD_OP(FW_VI_MAC_CMD) | FW_CMD_REQUEST |
  2419. FW_CMD_WRITE | (free ? FW_CMD_EXEC : 0) |
  2420. FW_VI_MAC_CMD_VIID(viid));
  2421. c.freemacs_to_len16 = htonl(FW_VI_MAC_CMD_FREEMACS(free) |
  2422. FW_CMD_LEN16((naddr + 2) / 2));
  2423. for (i = 0, p = c.u.exact; i < naddr; i++, p++) {
  2424. p->valid_to_idx = htons(FW_VI_MAC_CMD_VALID |
  2425. FW_VI_MAC_CMD_IDX(FW_VI_MAC_ADD_MAC));
  2426. memcpy(p->macaddr, addr[i], sizeof(p->macaddr));
  2427. }
  2428. ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
  2429. if (ret)
  2430. return ret;
  2431. for (i = 0, p = c.u.exact; i < naddr; i++, p++) {
  2432. u16 index = FW_VI_MAC_CMD_IDX_GET(ntohs(p->valid_to_idx));
  2433. if (idx)
  2434. idx[i] = index >= NEXACT_MAC ? 0xffff : index;
  2435. if (index < NEXACT_MAC)
  2436. ret++;
  2437. else if (hash)
  2438. *hash |= (1 << hash_mac_addr(addr[i]));
  2439. }
  2440. return ret;
  2441. }
  2442. /**
  2443. * t4_change_mac - modifies the exact-match filter for a MAC address
  2444. * @adap: the adapter
  2445. * @mbox: mailbox to use for the FW command
  2446. * @viid: the VI id
  2447. * @idx: index of existing filter for old value of MAC address, or -1
  2448. * @addr: the new MAC address value
  2449. * @persist: whether a new MAC allocation should be persistent
  2450. * @add_smt: if true also add the address to the HW SMT
  2451. *
  2452. * Modifies an exact-match filter and sets it to the new MAC address.
  2453. * Note that in general it is not possible to modify the value of a given
  2454. * filter so the generic way to modify an address filter is to free the one
  2455. * being used by the old address value and allocate a new filter for the
  2456. * new address value. @idx can be -1 if the address is a new addition.
  2457. *
  2458. * Returns a negative error number or the index of the filter with the new
  2459. * MAC value.
  2460. */
  2461. int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
  2462. int idx, const u8 *addr, bool persist, bool add_smt)
  2463. {
  2464. int ret, mode;
  2465. struct fw_vi_mac_cmd c;
  2466. struct fw_vi_mac_exact *p = c.u.exact;
  2467. if (idx < 0) /* new allocation */
  2468. idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
  2469. mode = add_smt ? FW_VI_MAC_SMT_AND_MPSTCAM : FW_VI_MAC_MPS_TCAM_ENTRY;
  2470. memset(&c, 0, sizeof(c));
  2471. c.op_to_viid = htonl(FW_CMD_OP(FW_VI_MAC_CMD) | FW_CMD_REQUEST |
  2472. FW_CMD_WRITE | FW_VI_MAC_CMD_VIID(viid));
  2473. c.freemacs_to_len16 = htonl(FW_CMD_LEN16(1));
  2474. p->valid_to_idx = htons(FW_VI_MAC_CMD_VALID |
  2475. FW_VI_MAC_CMD_SMAC_RESULT(mode) |
  2476. FW_VI_MAC_CMD_IDX(idx));
  2477. memcpy(p->macaddr, addr, sizeof(p->macaddr));
  2478. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  2479. if (ret == 0) {
  2480. ret = FW_VI_MAC_CMD_IDX_GET(ntohs(p->valid_to_idx));
  2481. if (ret >= NEXACT_MAC)
  2482. ret = -ENOMEM;
  2483. }
  2484. return ret;
  2485. }
  2486. /**
  2487. * t4_set_addr_hash - program the MAC inexact-match hash filter
  2488. * @adap: the adapter
  2489. * @mbox: mailbox to use for the FW command
  2490. * @viid: the VI id
  2491. * @ucast: whether the hash filter should also match unicast addresses
  2492. * @vec: the value to be written to the hash filter
  2493. * @sleep_ok: call is allowed to sleep
  2494. *
  2495. * Sets the 64-bit inexact-match hash filter for a virtual interface.
  2496. */
  2497. int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
  2498. bool ucast, u64 vec, bool sleep_ok)
  2499. {
  2500. struct fw_vi_mac_cmd c;
  2501. memset(&c, 0, sizeof(c));
  2502. c.op_to_viid = htonl(FW_CMD_OP(FW_VI_MAC_CMD) | FW_CMD_REQUEST |
  2503. FW_CMD_WRITE | FW_VI_ENABLE_CMD_VIID(viid));
  2504. c.freemacs_to_len16 = htonl(FW_VI_MAC_CMD_HASHVECEN |
  2505. FW_VI_MAC_CMD_HASHUNIEN(ucast) |
  2506. FW_CMD_LEN16(1));
  2507. c.u.hash.hashvec = cpu_to_be64(vec);
  2508. return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
  2509. }
  2510. /**
  2511. * t4_enable_vi - enable/disable a virtual interface
  2512. * @adap: the adapter
  2513. * @mbox: mailbox to use for the FW command
  2514. * @viid: the VI id
  2515. * @rx_en: 1=enable Rx, 0=disable Rx
  2516. * @tx_en: 1=enable Tx, 0=disable Tx
  2517. *
  2518. * Enables/disables a virtual interface.
  2519. */
  2520. int t4_enable_vi(struct adapter *adap, unsigned int mbox, unsigned int viid,
  2521. bool rx_en, bool tx_en)
  2522. {
  2523. struct fw_vi_enable_cmd c;
  2524. memset(&c, 0, sizeof(c));
  2525. c.op_to_viid = htonl(FW_CMD_OP(FW_VI_ENABLE_CMD) | FW_CMD_REQUEST |
  2526. FW_CMD_EXEC | FW_VI_ENABLE_CMD_VIID(viid));
  2527. c.ien_to_len16 = htonl(FW_VI_ENABLE_CMD_IEN(rx_en) |
  2528. FW_VI_ENABLE_CMD_EEN(tx_en) | FW_LEN16(c));
  2529. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2530. }
  2531. /**
  2532. * t4_identify_port - identify a VI's port by blinking its LED
  2533. * @adap: the adapter
  2534. * @mbox: mailbox to use for the FW command
  2535. * @viid: the VI id
  2536. * @nblinks: how many times to blink LED at 2.5 Hz
  2537. *
  2538. * Identifies a VI's port by blinking its LED.
  2539. */
  2540. int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
  2541. unsigned int nblinks)
  2542. {
  2543. struct fw_vi_enable_cmd c;
  2544. c.op_to_viid = htonl(FW_CMD_OP(FW_VI_ENABLE_CMD) | FW_CMD_REQUEST |
  2545. FW_CMD_EXEC | FW_VI_ENABLE_CMD_VIID(viid));
  2546. c.ien_to_len16 = htonl(FW_VI_ENABLE_CMD_LED | FW_LEN16(c));
  2547. c.blinkdur = htons(nblinks);
  2548. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2549. }
  2550. /**
  2551. * t4_iq_start_stop - enable/disable an ingress queue and its FLs
  2552. * @adap: the adapter
  2553. * @mbox: mailbox to use for the FW command
  2554. * @start: %true to enable the queues, %false to disable them
  2555. * @pf: the PF owning the queues
  2556. * @vf: the VF owning the queues
  2557. * @iqid: ingress queue id
  2558. * @fl0id: FL0 queue id or 0xffff if no attached FL0
  2559. * @fl1id: FL1 queue id or 0xffff if no attached FL1
  2560. *
  2561. * Starts or stops an ingress queue and its associated FLs, if any.
  2562. */
  2563. int t4_iq_start_stop(struct adapter *adap, unsigned int mbox, bool start,
  2564. unsigned int pf, unsigned int vf, unsigned int iqid,
  2565. unsigned int fl0id, unsigned int fl1id)
  2566. {
  2567. struct fw_iq_cmd c;
  2568. memset(&c, 0, sizeof(c));
  2569. c.op_to_vfn = htonl(FW_CMD_OP(FW_IQ_CMD) | FW_CMD_REQUEST |
  2570. FW_CMD_EXEC | FW_IQ_CMD_PFN(pf) |
  2571. FW_IQ_CMD_VFN(vf));
  2572. c.alloc_to_len16 = htonl(FW_IQ_CMD_IQSTART(start) |
  2573. FW_IQ_CMD_IQSTOP(!start) | FW_LEN16(c));
  2574. c.iqid = htons(iqid);
  2575. c.fl0id = htons(fl0id);
  2576. c.fl1id = htons(fl1id);
  2577. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2578. }
  2579. /**
  2580. * t4_iq_free - free an ingress queue and its FLs
  2581. * @adap: the adapter
  2582. * @mbox: mailbox to use for the FW command
  2583. * @pf: the PF owning the queues
  2584. * @vf: the VF owning the queues
  2585. * @iqtype: the ingress queue type
  2586. * @iqid: ingress queue id
  2587. * @fl0id: FL0 queue id or 0xffff if no attached FL0
  2588. * @fl1id: FL1 queue id or 0xffff if no attached FL1
  2589. *
  2590. * Frees an ingress queue and its associated FLs, if any.
  2591. */
  2592. int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  2593. unsigned int vf, unsigned int iqtype, unsigned int iqid,
  2594. unsigned int fl0id, unsigned int fl1id)
  2595. {
  2596. struct fw_iq_cmd c;
  2597. memset(&c, 0, sizeof(c));
  2598. c.op_to_vfn = htonl(FW_CMD_OP(FW_IQ_CMD) | FW_CMD_REQUEST |
  2599. FW_CMD_EXEC | FW_IQ_CMD_PFN(pf) |
  2600. FW_IQ_CMD_VFN(vf));
  2601. c.alloc_to_len16 = htonl(FW_IQ_CMD_FREE | FW_LEN16(c));
  2602. c.type_to_iqandstindex = htonl(FW_IQ_CMD_TYPE(iqtype));
  2603. c.iqid = htons(iqid);
  2604. c.fl0id = htons(fl0id);
  2605. c.fl1id = htons(fl1id);
  2606. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2607. }
  2608. /**
  2609. * t4_eth_eq_free - free an Ethernet egress queue
  2610. * @adap: the adapter
  2611. * @mbox: mailbox to use for the FW command
  2612. * @pf: the PF owning the queue
  2613. * @vf: the VF owning the queue
  2614. * @eqid: egress queue id
  2615. *
  2616. * Frees an Ethernet egress queue.
  2617. */
  2618. int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  2619. unsigned int vf, unsigned int eqid)
  2620. {
  2621. struct fw_eq_eth_cmd c;
  2622. memset(&c, 0, sizeof(c));
  2623. c.op_to_vfn = htonl(FW_CMD_OP(FW_EQ_ETH_CMD) | FW_CMD_REQUEST |
  2624. FW_CMD_EXEC | FW_EQ_ETH_CMD_PFN(pf) |
  2625. FW_EQ_ETH_CMD_VFN(vf));
  2626. c.alloc_to_len16 = htonl(FW_EQ_ETH_CMD_FREE | FW_LEN16(c));
  2627. c.eqid_pkd = htonl(FW_EQ_ETH_CMD_EQID(eqid));
  2628. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2629. }
  2630. /**
  2631. * t4_ctrl_eq_free - free a control egress queue
  2632. * @adap: the adapter
  2633. * @mbox: mailbox to use for the FW command
  2634. * @pf: the PF owning the queue
  2635. * @vf: the VF owning the queue
  2636. * @eqid: egress queue id
  2637. *
  2638. * Frees a control egress queue.
  2639. */
  2640. int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  2641. unsigned int vf, unsigned int eqid)
  2642. {
  2643. struct fw_eq_ctrl_cmd c;
  2644. memset(&c, 0, sizeof(c));
  2645. c.op_to_vfn = htonl(FW_CMD_OP(FW_EQ_CTRL_CMD) | FW_CMD_REQUEST |
  2646. FW_CMD_EXEC | FW_EQ_CTRL_CMD_PFN(pf) |
  2647. FW_EQ_CTRL_CMD_VFN(vf));
  2648. c.alloc_to_len16 = htonl(FW_EQ_CTRL_CMD_FREE | FW_LEN16(c));
  2649. c.cmpliqid_eqid = htonl(FW_EQ_CTRL_CMD_EQID(eqid));
  2650. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2651. }
  2652. /**
  2653. * t4_ofld_eq_free - free an offload egress queue
  2654. * @adap: the adapter
  2655. * @mbox: mailbox to use for the FW command
  2656. * @pf: the PF owning the queue
  2657. * @vf: the VF owning the queue
  2658. * @eqid: egress queue id
  2659. *
  2660. * Frees a control egress queue.
  2661. */
  2662. int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  2663. unsigned int vf, unsigned int eqid)
  2664. {
  2665. struct fw_eq_ofld_cmd c;
  2666. memset(&c, 0, sizeof(c));
  2667. c.op_to_vfn = htonl(FW_CMD_OP(FW_EQ_OFLD_CMD) | FW_CMD_REQUEST |
  2668. FW_CMD_EXEC | FW_EQ_OFLD_CMD_PFN(pf) |
  2669. FW_EQ_OFLD_CMD_VFN(vf));
  2670. c.alloc_to_len16 = htonl(FW_EQ_OFLD_CMD_FREE | FW_LEN16(c));
  2671. c.eqid_pkd = htonl(FW_EQ_OFLD_CMD_EQID(eqid));
  2672. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  2673. }
  2674. /**
  2675. * t4_handle_fw_rpl - process a FW reply message
  2676. * @adap: the adapter
  2677. * @rpl: start of the FW message
  2678. *
  2679. * Processes a FW message, such as link state change messages.
  2680. */
  2681. int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl)
  2682. {
  2683. u8 opcode = *(const u8 *)rpl;
  2684. if (opcode == FW_PORT_CMD) { /* link/module state change message */
  2685. int speed = 0, fc = 0;
  2686. const struct fw_port_cmd *p = (void *)rpl;
  2687. int chan = FW_PORT_CMD_PORTID_GET(ntohl(p->op_to_portid));
  2688. int port = adap->chan_map[chan];
  2689. struct port_info *pi = adap2pinfo(adap, port);
  2690. struct link_config *lc = &pi->link_cfg;
  2691. u32 stat = ntohl(p->u.info.lstatus_to_modtype);
  2692. int link_ok = (stat & FW_PORT_CMD_LSTATUS) != 0;
  2693. u32 mod = FW_PORT_CMD_MODTYPE_GET(stat);
  2694. if (stat & FW_PORT_CMD_RXPAUSE)
  2695. fc |= PAUSE_RX;
  2696. if (stat & FW_PORT_CMD_TXPAUSE)
  2697. fc |= PAUSE_TX;
  2698. if (stat & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_100M))
  2699. speed = SPEED_100;
  2700. else if (stat & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_1G))
  2701. speed = SPEED_1000;
  2702. else if (stat & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_10G))
  2703. speed = SPEED_10000;
  2704. if (link_ok != lc->link_ok || speed != lc->speed ||
  2705. fc != lc->fc) { /* something changed */
  2706. lc->link_ok = link_ok;
  2707. lc->speed = speed;
  2708. lc->fc = fc;
  2709. t4_os_link_changed(adap, port, link_ok);
  2710. }
  2711. if (mod != pi->mod_type) {
  2712. pi->mod_type = mod;
  2713. t4_os_portmod_changed(adap, port);
  2714. }
  2715. }
  2716. return 0;
  2717. }
  2718. static void __devinit get_pci_mode(struct adapter *adapter,
  2719. struct pci_params *p)
  2720. {
  2721. u16 val;
  2722. u32 pcie_cap = pci_pcie_cap(adapter->pdev);
  2723. if (pcie_cap) {
  2724. pci_read_config_word(adapter->pdev, pcie_cap + PCI_EXP_LNKSTA,
  2725. &val);
  2726. p->speed = val & PCI_EXP_LNKSTA_CLS;
  2727. p->width = (val & PCI_EXP_LNKSTA_NLW) >> 4;
  2728. }
  2729. }
  2730. /**
  2731. * init_link_config - initialize a link's SW state
  2732. * @lc: structure holding the link state
  2733. * @caps: link capabilities
  2734. *
  2735. * Initializes the SW state maintained for each link, including the link's
  2736. * capabilities and default speed/flow-control/autonegotiation settings.
  2737. */
  2738. static void __devinit init_link_config(struct link_config *lc,
  2739. unsigned int caps)
  2740. {
  2741. lc->supported = caps;
  2742. lc->requested_speed = 0;
  2743. lc->speed = 0;
  2744. lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
  2745. if (lc->supported & FW_PORT_CAP_ANEG) {
  2746. lc->advertising = lc->supported & ADVERT_MASK;
  2747. lc->autoneg = AUTONEG_ENABLE;
  2748. lc->requested_fc |= PAUSE_AUTONEG;
  2749. } else {
  2750. lc->advertising = 0;
  2751. lc->autoneg = AUTONEG_DISABLE;
  2752. }
  2753. }
  2754. static int __devinit wait_dev_ready(struct adapter *adap)
  2755. {
  2756. if (t4_read_reg(adap, PL_WHOAMI) != 0xffffffff)
  2757. return 0;
  2758. msleep(500);
  2759. return t4_read_reg(adap, PL_WHOAMI) != 0xffffffff ? 0 : -EIO;
  2760. }
  2761. /**
  2762. * t4_prep_adapter - prepare SW and HW for operation
  2763. * @adapter: the adapter
  2764. * @reset: if true perform a HW reset
  2765. *
  2766. * Initialize adapter SW state for the various HW modules, set initial
  2767. * values for some adapter tunables, take PHYs out of reset, and
  2768. * initialize the MDIO interface.
  2769. */
  2770. int __devinit t4_prep_adapter(struct adapter *adapter)
  2771. {
  2772. int ret;
  2773. ret = wait_dev_ready(adapter);
  2774. if (ret < 0)
  2775. return ret;
  2776. get_pci_mode(adapter, &adapter->params.pci);
  2777. adapter->params.rev = t4_read_reg(adapter, PL_REV);
  2778. ret = get_vpd_params(adapter, &adapter->params.vpd);
  2779. if (ret < 0)
  2780. return ret;
  2781. init_cong_ctrl(adapter->params.a_wnd, adapter->params.b_wnd);
  2782. /*
  2783. * Default port for debugging in case we can't reach FW.
  2784. */
  2785. adapter->params.nports = 1;
  2786. adapter->params.portvec = 1;
  2787. return 0;
  2788. }
  2789. int __devinit t4_port_init(struct adapter *adap, int mbox, int pf, int vf)
  2790. {
  2791. u8 addr[6];
  2792. int ret, i, j = 0;
  2793. struct fw_port_cmd c;
  2794. memset(&c, 0, sizeof(c));
  2795. for_each_port(adap, i) {
  2796. unsigned int rss_size;
  2797. struct port_info *p = adap2pinfo(adap, i);
  2798. while ((adap->params.portvec & (1 << j)) == 0)
  2799. j++;
  2800. c.op_to_portid = htonl(FW_CMD_OP(FW_PORT_CMD) |
  2801. FW_CMD_REQUEST | FW_CMD_READ |
  2802. FW_PORT_CMD_PORTID(j));
  2803. c.action_to_len16 = htonl(
  2804. FW_PORT_CMD_ACTION(FW_PORT_ACTION_GET_PORT_INFO) |
  2805. FW_LEN16(c));
  2806. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  2807. if (ret)
  2808. return ret;
  2809. ret = t4_alloc_vi(adap, mbox, j, pf, vf, 1, addr, &rss_size);
  2810. if (ret < 0)
  2811. return ret;
  2812. p->viid = ret;
  2813. p->tx_chan = j;
  2814. p->lport = j;
  2815. p->rss_size = rss_size;
  2816. memcpy(adap->port[i]->dev_addr, addr, ETH_ALEN);
  2817. memcpy(adap->port[i]->perm_addr, addr, ETH_ALEN);
  2818. ret = ntohl(c.u.info.lstatus_to_modtype);
  2819. p->mdio_addr = (ret & FW_PORT_CMD_MDIOCAP) ?
  2820. FW_PORT_CMD_MDIOADDR_GET(ret) : -1;
  2821. p->port_type = FW_PORT_CMD_PTYPE_GET(ret);
  2822. p->mod_type = FW_PORT_CMD_MODTYPE_GET(ret);
  2823. init_link_config(&p->link_cfg, ntohs(c.u.info.pcap));
  2824. j++;
  2825. }
  2826. return 0;
  2827. }