t4_hw.c 96 KB

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