fman.c 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962
  1. /*
  2. * Copyright 2008-2015 Freescale Semiconductor Inc.
  3. * Copyright 2020 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of Freescale Semiconductor nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. *
  17. * ALTERNATIVELY, this software may be distributed under the terms of the
  18. * GNU General Public License ("GPL") as published by the Free Software
  19. * Foundation, either version 2 of that License or (at your option) any
  20. * later version.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  23. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  26. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  34. #include <linux/fsl/guts.h>
  35. #include <linux/slab.h>
  36. #include <linux/delay.h>
  37. #include <linux/module.h>
  38. #include <linux/of_platform.h>
  39. #include <linux/clk.h>
  40. #include <linux/of_address.h>
  41. #include <linux/of_irq.h>
  42. #include <linux/interrupt.h>
  43. #include <linux/libfdt_env.h>
  44. #include "fman.h"
  45. #include "fman_muram.h"
  46. #include "fman_keygen.h"
  47. /* General defines */
  48. #define FMAN_LIODN_TBL 64 /* size of LIODN table */
  49. #define MAX_NUM_OF_MACS 10
  50. #define FM_NUM_OF_FMAN_CTRL_EVENT_REGS 4
  51. #define BASE_RX_PORTID 0x08
  52. #define BASE_TX_PORTID 0x28
  53. /* Modules registers offsets */
  54. #define BMI_OFFSET 0x00080000
  55. #define QMI_OFFSET 0x00080400
  56. #define KG_OFFSET 0x000C1000
  57. #define DMA_OFFSET 0x000C2000
  58. #define FPM_OFFSET 0x000C3000
  59. #define IMEM_OFFSET 0x000C4000
  60. #define HWP_OFFSET 0x000C7000
  61. #define CGP_OFFSET 0x000DB000
  62. /* Exceptions bit map */
  63. #define EX_DMA_BUS_ERROR 0x80000000
  64. #define EX_DMA_READ_ECC 0x40000000
  65. #define EX_DMA_SYSTEM_WRITE_ECC 0x20000000
  66. #define EX_DMA_FM_WRITE_ECC 0x10000000
  67. #define EX_FPM_STALL_ON_TASKS 0x08000000
  68. #define EX_FPM_SINGLE_ECC 0x04000000
  69. #define EX_FPM_DOUBLE_ECC 0x02000000
  70. #define EX_QMI_SINGLE_ECC 0x01000000
  71. #define EX_QMI_DEQ_FROM_UNKNOWN_PORTID 0x00800000
  72. #define EX_QMI_DOUBLE_ECC 0x00400000
  73. #define EX_BMI_LIST_RAM_ECC 0x00200000
  74. #define EX_BMI_STORAGE_PROFILE_ECC 0x00100000
  75. #define EX_BMI_STATISTICS_RAM_ECC 0x00080000
  76. #define EX_IRAM_ECC 0x00040000
  77. #define EX_MURAM_ECC 0x00020000
  78. #define EX_BMI_DISPATCH_RAM_ECC 0x00010000
  79. #define EX_DMA_SINGLE_PORT_ECC 0x00008000
  80. /* DMA defines */
  81. /* masks */
  82. #define DMA_MODE_BER 0x00200000
  83. #define DMA_MODE_ECC 0x00000020
  84. #define DMA_MODE_SECURE_PROT 0x00000800
  85. #define DMA_MODE_AXI_DBG_MASK 0x0F000000
  86. #define DMA_TRANSFER_PORTID_MASK 0xFF000000
  87. #define DMA_TRANSFER_TNUM_MASK 0x00FF0000
  88. #define DMA_TRANSFER_LIODN_MASK 0x00000FFF
  89. #define DMA_STATUS_BUS_ERR 0x08000000
  90. #define DMA_STATUS_READ_ECC 0x04000000
  91. #define DMA_STATUS_SYSTEM_WRITE_ECC 0x02000000
  92. #define DMA_STATUS_FM_WRITE_ECC 0x01000000
  93. #define DMA_STATUS_FM_SPDAT_ECC 0x00080000
  94. #define DMA_MODE_CACHE_OR_SHIFT 30
  95. #define DMA_MODE_AXI_DBG_SHIFT 24
  96. #define DMA_MODE_CEN_SHIFT 13
  97. #define DMA_MODE_CEN_MASK 0x00000007
  98. #define DMA_MODE_DBG_SHIFT 7
  99. #define DMA_MODE_AID_MODE_SHIFT 4
  100. #define DMA_THRESH_COMMQ_SHIFT 24
  101. #define DMA_THRESH_READ_INT_BUF_SHIFT 16
  102. #define DMA_THRESH_READ_INT_BUF_MASK 0x0000003f
  103. #define DMA_THRESH_WRITE_INT_BUF_MASK 0x0000003f
  104. #define DMA_TRANSFER_PORTID_SHIFT 24
  105. #define DMA_TRANSFER_TNUM_SHIFT 16
  106. #define DMA_CAM_SIZEOF_ENTRY 0x40
  107. #define DMA_CAM_UNITS 8
  108. #define DMA_LIODN_SHIFT 16
  109. #define DMA_LIODN_BASE_MASK 0x00000FFF
  110. /* FPM defines */
  111. #define FPM_EV_MASK_DOUBLE_ECC 0x80000000
  112. #define FPM_EV_MASK_STALL 0x40000000
  113. #define FPM_EV_MASK_SINGLE_ECC 0x20000000
  114. #define FPM_EV_MASK_RELEASE_FM 0x00010000
  115. #define FPM_EV_MASK_DOUBLE_ECC_EN 0x00008000
  116. #define FPM_EV_MASK_STALL_EN 0x00004000
  117. #define FPM_EV_MASK_SINGLE_ECC_EN 0x00002000
  118. #define FPM_EV_MASK_EXTERNAL_HALT 0x00000008
  119. #define FPM_EV_MASK_ECC_ERR_HALT 0x00000004
  120. #define FPM_RAM_MURAM_ECC 0x00008000
  121. #define FPM_RAM_IRAM_ECC 0x00004000
  122. #define FPM_IRAM_ECC_ERR_EX_EN 0x00020000
  123. #define FPM_MURAM_ECC_ERR_EX_EN 0x00040000
  124. #define FPM_RAM_IRAM_ECC_EN 0x40000000
  125. #define FPM_RAM_RAMS_ECC_EN 0x80000000
  126. #define FPM_RAM_RAMS_ECC_EN_SRC_SEL 0x08000000
  127. #define FPM_REV1_MAJOR_MASK 0x0000FF00
  128. #define FPM_REV1_MINOR_MASK 0x000000FF
  129. #define FPM_DISP_LIMIT_SHIFT 24
  130. #define FPM_PRT_FM_CTL1 0x00000001
  131. #define FPM_PRT_FM_CTL2 0x00000002
  132. #define FPM_PORT_FM_CTL_PORTID_SHIFT 24
  133. #define FPM_PRC_ORA_FM_CTL_SEL_SHIFT 16
  134. #define FPM_THR1_PRS_SHIFT 24
  135. #define FPM_THR1_KG_SHIFT 16
  136. #define FPM_THR1_PLCR_SHIFT 8
  137. #define FPM_THR1_BMI_SHIFT 0
  138. #define FPM_THR2_QMI_ENQ_SHIFT 24
  139. #define FPM_THR2_QMI_DEQ_SHIFT 0
  140. #define FPM_THR2_FM_CTL1_SHIFT 16
  141. #define FPM_THR2_FM_CTL2_SHIFT 8
  142. #define FPM_EV_MASK_CAT_ERR_SHIFT 1
  143. #define FPM_EV_MASK_DMA_ERR_SHIFT 0
  144. #define FPM_REV1_MAJOR_SHIFT 8
  145. #define FPM_RSTC_FM_RESET 0x80000000
  146. #define FPM_RSTC_MAC0_RESET 0x40000000
  147. #define FPM_RSTC_MAC1_RESET 0x20000000
  148. #define FPM_RSTC_MAC2_RESET 0x10000000
  149. #define FPM_RSTC_MAC3_RESET 0x08000000
  150. #define FPM_RSTC_MAC8_RESET 0x04000000
  151. #define FPM_RSTC_MAC4_RESET 0x02000000
  152. #define FPM_RSTC_MAC5_RESET 0x01000000
  153. #define FPM_RSTC_MAC6_RESET 0x00800000
  154. #define FPM_RSTC_MAC7_RESET 0x00400000
  155. #define FPM_RSTC_MAC9_RESET 0x00200000
  156. #define FPM_TS_INT_SHIFT 16
  157. #define FPM_TS_CTL_EN 0x80000000
  158. /* BMI defines */
  159. #define BMI_INIT_START 0x80000000
  160. #define BMI_ERR_INTR_EN_STORAGE_PROFILE_ECC 0x80000000
  161. #define BMI_ERR_INTR_EN_LIST_RAM_ECC 0x40000000
  162. #define BMI_ERR_INTR_EN_STATISTICS_RAM_ECC 0x20000000
  163. #define BMI_ERR_INTR_EN_DISPATCH_RAM_ECC 0x10000000
  164. #define BMI_NUM_OF_TASKS_MASK 0x3F000000
  165. #define BMI_NUM_OF_EXTRA_TASKS_MASK 0x000F0000
  166. #define BMI_NUM_OF_DMAS_MASK 0x00000F00
  167. #define BMI_NUM_OF_EXTRA_DMAS_MASK 0x0000000F
  168. #define BMI_FIFO_SIZE_MASK 0x000003FF
  169. #define BMI_EXTRA_FIFO_SIZE_MASK 0x03FF0000
  170. #define BMI_CFG2_DMAS_MASK 0x0000003F
  171. #define BMI_CFG2_TASKS_MASK 0x0000003F
  172. #define BMI_CFG2_TASKS_SHIFT 16
  173. #define BMI_CFG2_DMAS_SHIFT 0
  174. #define BMI_CFG1_FIFO_SIZE_SHIFT 16
  175. #define BMI_NUM_OF_TASKS_SHIFT 24
  176. #define BMI_EXTRA_NUM_OF_TASKS_SHIFT 16
  177. #define BMI_NUM_OF_DMAS_SHIFT 8
  178. #define BMI_EXTRA_NUM_OF_DMAS_SHIFT 0
  179. #define BMI_FIFO_ALIGN 0x100
  180. #define BMI_EXTRA_FIFO_SIZE_SHIFT 16
  181. /* QMI defines */
  182. #define QMI_CFG_ENQ_EN 0x80000000
  183. #define QMI_CFG_DEQ_EN 0x40000000
  184. #define QMI_CFG_EN_COUNTERS 0x10000000
  185. #define QMI_CFG_DEQ_MASK 0x0000003F
  186. #define QMI_CFG_ENQ_MASK 0x00003F00
  187. #define QMI_CFG_ENQ_SHIFT 8
  188. #define QMI_ERR_INTR_EN_DOUBLE_ECC 0x80000000
  189. #define QMI_ERR_INTR_EN_DEQ_FROM_DEF 0x40000000
  190. #define QMI_INTR_EN_SINGLE_ECC 0x80000000
  191. #define QMI_GS_HALT_NOT_BUSY 0x00000002
  192. /* HWP defines */
  193. #define HWP_RPIMAC_PEN 0x00000001
  194. /* IRAM defines */
  195. #define IRAM_IADD_AIE 0x80000000
  196. #define IRAM_READY 0x80000000
  197. /* Default values */
  198. #define DEFAULT_CATASTROPHIC_ERR 0
  199. #define DEFAULT_DMA_ERR 0
  200. #define DEFAULT_AID_MODE FMAN_DMA_AID_OUT_TNUM
  201. #define DEFAULT_DMA_COMM_Q_LOW 0x2A
  202. #define DEFAULT_DMA_COMM_Q_HIGH 0x3F
  203. #define DEFAULT_CACHE_OVERRIDE 0
  204. #define DEFAULT_DMA_CAM_NUM_OF_ENTRIES 64
  205. #define DEFAULT_DMA_DBG_CNT_MODE 0
  206. #define DEFAULT_DMA_SOS_EMERGENCY 0
  207. #define DEFAULT_DMA_WATCHDOG 0
  208. #define DEFAULT_DISP_LIMIT 0
  209. #define DEFAULT_PRS_DISP_TH 16
  210. #define DEFAULT_PLCR_DISP_TH 16
  211. #define DEFAULT_KG_DISP_TH 16
  212. #define DEFAULT_BMI_DISP_TH 16
  213. #define DEFAULT_QMI_ENQ_DISP_TH 16
  214. #define DEFAULT_QMI_DEQ_DISP_TH 16
  215. #define DEFAULT_FM_CTL1_DISP_TH 16
  216. #define DEFAULT_FM_CTL2_DISP_TH 16
  217. #define DFLT_AXI_DBG_NUM_OF_BEATS 1
  218. #define DFLT_DMA_READ_INT_BUF_LOW(dma_thresh_max_buf) \
  219. ((dma_thresh_max_buf + 1) / 2)
  220. #define DFLT_DMA_READ_INT_BUF_HIGH(dma_thresh_max_buf) \
  221. ((dma_thresh_max_buf + 1) * 3 / 4)
  222. #define DFLT_DMA_WRITE_INT_BUF_LOW(dma_thresh_max_buf) \
  223. ((dma_thresh_max_buf + 1) / 2)
  224. #define DFLT_DMA_WRITE_INT_BUF_HIGH(dma_thresh_max_buf)\
  225. ((dma_thresh_max_buf + 1) * 3 / 4)
  226. #define DMA_COMM_Q_LOW_FMAN_V3 0x2A
  227. #define DMA_COMM_Q_LOW_FMAN_V2(dma_thresh_max_commq) \
  228. ((dma_thresh_max_commq + 1) / 2)
  229. #define DFLT_DMA_COMM_Q_LOW(major, dma_thresh_max_commq) \
  230. ((major == 6) ? DMA_COMM_Q_LOW_FMAN_V3 : \
  231. DMA_COMM_Q_LOW_FMAN_V2(dma_thresh_max_commq))
  232. #define DMA_COMM_Q_HIGH_FMAN_V3 0x3f
  233. #define DMA_COMM_Q_HIGH_FMAN_V2(dma_thresh_max_commq) \
  234. ((dma_thresh_max_commq + 1) * 3 / 4)
  235. #define DFLT_DMA_COMM_Q_HIGH(major, dma_thresh_max_commq) \
  236. ((major == 6) ? DMA_COMM_Q_HIGH_FMAN_V3 : \
  237. DMA_COMM_Q_HIGH_FMAN_V2(dma_thresh_max_commq))
  238. #define TOTAL_NUM_OF_TASKS_FMAN_V3L 59
  239. #define TOTAL_NUM_OF_TASKS_FMAN_V3H 124
  240. #define DFLT_TOTAL_NUM_OF_TASKS(major, minor, bmi_max_num_of_tasks) \
  241. ((major == 6) ? ((minor == 1 || minor == 4) ? \
  242. TOTAL_NUM_OF_TASKS_FMAN_V3L : TOTAL_NUM_OF_TASKS_FMAN_V3H) : \
  243. bmi_max_num_of_tasks)
  244. #define DMA_CAM_NUM_OF_ENTRIES_FMAN_V3 64
  245. #define DMA_CAM_NUM_OF_ENTRIES_FMAN_V2 32
  246. #define DFLT_DMA_CAM_NUM_OF_ENTRIES(major) \
  247. (major == 6 ? DMA_CAM_NUM_OF_ENTRIES_FMAN_V3 : \
  248. DMA_CAM_NUM_OF_ENTRIES_FMAN_V2)
  249. #define FM_TIMESTAMP_1_USEC_BIT 8
  250. /* Defines used for enabling/disabling FMan interrupts */
  251. #define ERR_INTR_EN_DMA 0x00010000
  252. #define ERR_INTR_EN_FPM 0x80000000
  253. #define ERR_INTR_EN_BMI 0x00800000
  254. #define ERR_INTR_EN_QMI 0x00400000
  255. #define ERR_INTR_EN_MURAM 0x00040000
  256. #define ERR_INTR_EN_MAC0 0x00004000
  257. #define ERR_INTR_EN_MAC1 0x00002000
  258. #define ERR_INTR_EN_MAC2 0x00001000
  259. #define ERR_INTR_EN_MAC3 0x00000800
  260. #define ERR_INTR_EN_MAC4 0x00000400
  261. #define ERR_INTR_EN_MAC5 0x00000200
  262. #define ERR_INTR_EN_MAC6 0x00000100
  263. #define ERR_INTR_EN_MAC7 0x00000080
  264. #define ERR_INTR_EN_MAC8 0x00008000
  265. #define ERR_INTR_EN_MAC9 0x00000040
  266. #define INTR_EN_QMI 0x40000000
  267. #define INTR_EN_MAC0 0x00080000
  268. #define INTR_EN_MAC1 0x00040000
  269. #define INTR_EN_MAC2 0x00020000
  270. #define INTR_EN_MAC3 0x00010000
  271. #define INTR_EN_MAC4 0x00000040
  272. #define INTR_EN_MAC5 0x00000020
  273. #define INTR_EN_MAC6 0x00000008
  274. #define INTR_EN_MAC7 0x00000002
  275. #define INTR_EN_MAC8 0x00200000
  276. #define INTR_EN_MAC9 0x00100000
  277. #define INTR_EN_REV0 0x00008000
  278. #define INTR_EN_REV1 0x00004000
  279. #define INTR_EN_REV2 0x00002000
  280. #define INTR_EN_REV3 0x00001000
  281. #define INTR_EN_TMR 0x01000000
  282. enum fman_dma_aid_mode {
  283. FMAN_DMA_AID_OUT_PORT_ID = 0, /* 4 LSB of PORT_ID */
  284. FMAN_DMA_AID_OUT_TNUM /* 4 LSB of TNUM */
  285. };
  286. struct fman_iram_regs {
  287. u32 iadd; /* FM IRAM instruction address register */
  288. u32 idata; /* FM IRAM instruction data register */
  289. u32 itcfg; /* FM IRAM timing config register */
  290. u32 iready; /* FM IRAM ready register */
  291. };
  292. struct fman_fpm_regs {
  293. u32 fmfp_tnc; /* FPM TNUM Control 0x00 */
  294. u32 fmfp_prc; /* FPM Port_ID FmCtl Association 0x04 */
  295. u32 fmfp_brkc; /* FPM Breakpoint Control 0x08 */
  296. u32 fmfp_mxd; /* FPM Flush Control 0x0c */
  297. u32 fmfp_dist1; /* FPM Dispatch Thresholds1 0x10 */
  298. u32 fmfp_dist2; /* FPM Dispatch Thresholds2 0x14 */
  299. u32 fm_epi; /* FM Error Pending Interrupts 0x18 */
  300. u32 fm_rie; /* FM Error Interrupt Enable 0x1c */
  301. u32 fmfp_fcev[4]; /* FPM FMan-Controller Event 1-4 0x20-0x2f */
  302. u32 res0030[4]; /* res 0x30 - 0x3f */
  303. u32 fmfp_cee[4]; /* PM FMan-Controller Event 1-4 0x40-0x4f */
  304. u32 res0050[4]; /* res 0x50-0x5f */
  305. u32 fmfp_tsc1; /* FPM TimeStamp Control1 0x60 */
  306. u32 fmfp_tsc2; /* FPM TimeStamp Control2 0x64 */
  307. u32 fmfp_tsp; /* FPM Time Stamp 0x68 */
  308. u32 fmfp_tsf; /* FPM Time Stamp Fraction 0x6c */
  309. u32 fm_rcr; /* FM Rams Control 0x70 */
  310. u32 fmfp_extc; /* FPM External Requests Control 0x74 */
  311. u32 fmfp_ext1; /* FPM External Requests Config1 0x78 */
  312. u32 fmfp_ext2; /* FPM External Requests Config2 0x7c */
  313. u32 fmfp_drd[16]; /* FPM Data_Ram Data 0-15 0x80 - 0xbf */
  314. u32 fmfp_dra; /* FPM Data Ram Access 0xc0 */
  315. u32 fm_ip_rev_1; /* FM IP Block Revision 1 0xc4 */
  316. u32 fm_ip_rev_2; /* FM IP Block Revision 2 0xc8 */
  317. u32 fm_rstc; /* FM Reset Command 0xcc */
  318. u32 fm_cld; /* FM Classifier Debug 0xd0 */
  319. u32 fm_npi; /* FM Normal Pending Interrupts 0xd4 */
  320. u32 fmfp_exte; /* FPM External Requests Enable 0xd8 */
  321. u32 fmfp_ee; /* FPM Event&Mask 0xdc */
  322. u32 fmfp_cev[4]; /* FPM CPU Event 1-4 0xe0-0xef */
  323. u32 res00f0[4]; /* res 0xf0-0xff */
  324. u32 fmfp_ps[50]; /* FPM Port Status 0x100-0x1c7 */
  325. u32 res01c8[14]; /* res 0x1c8-0x1ff */
  326. u32 fmfp_clfabc; /* FPM CLFABC 0x200 */
  327. u32 fmfp_clfcc; /* FPM CLFCC 0x204 */
  328. u32 fmfp_clfaval; /* FPM CLFAVAL 0x208 */
  329. u32 fmfp_clfbval; /* FPM CLFBVAL 0x20c */
  330. u32 fmfp_clfcval; /* FPM CLFCVAL 0x210 */
  331. u32 fmfp_clfamsk; /* FPM CLFAMSK 0x214 */
  332. u32 fmfp_clfbmsk; /* FPM CLFBMSK 0x218 */
  333. u32 fmfp_clfcmsk; /* FPM CLFCMSK 0x21c */
  334. u32 fmfp_clfamc; /* FPM CLFAMC 0x220 */
  335. u32 fmfp_clfbmc; /* FPM CLFBMC 0x224 */
  336. u32 fmfp_clfcmc; /* FPM CLFCMC 0x228 */
  337. u32 fmfp_decceh; /* FPM DECCEH 0x22c */
  338. u32 res0230[116]; /* res 0x230 - 0x3ff */
  339. u32 fmfp_ts[128]; /* 0x400: FPM Task Status 0x400 - 0x5ff */
  340. u32 res0600[0x400 - 384];
  341. };
  342. struct fman_bmi_regs {
  343. u32 fmbm_init; /* BMI Initialization 0x00 */
  344. u32 fmbm_cfg1; /* BMI Configuration 1 0x04 */
  345. u32 fmbm_cfg2; /* BMI Configuration 2 0x08 */
  346. u32 res000c[5]; /* 0x0c - 0x1f */
  347. u32 fmbm_ievr; /* Interrupt Event Register 0x20 */
  348. u32 fmbm_ier; /* Interrupt Enable Register 0x24 */
  349. u32 fmbm_ifr; /* Interrupt Force Register 0x28 */
  350. u32 res002c[5]; /* 0x2c - 0x3f */
  351. u32 fmbm_arb[8]; /* BMI Arbitration 0x40 - 0x5f */
  352. u32 res0060[12]; /* 0x60 - 0x8f */
  353. u32 fmbm_dtc[3]; /* Debug Trap Counter 0x90 - 0x9b */
  354. u32 res009c; /* 0x9c */
  355. u32 fmbm_dcv[3][4]; /* Debug Compare val 0xa0-0xcf */
  356. u32 fmbm_dcm[3][4]; /* Debug Compare Mask 0xd0-0xff */
  357. u32 fmbm_gde; /* BMI Global Debug Enable 0x100 */
  358. u32 fmbm_pp[63]; /* BMI Port Parameters 0x104 - 0x1ff */
  359. u32 res0200; /* 0x200 */
  360. u32 fmbm_pfs[63]; /* BMI Port FIFO Size 0x204 - 0x2ff */
  361. u32 res0300; /* 0x300 */
  362. u32 fmbm_spliodn[63]; /* Port Partition ID 0x304 - 0x3ff */
  363. };
  364. struct fman_qmi_regs {
  365. u32 fmqm_gc; /* General Configuration Register 0x00 */
  366. u32 res0004; /* 0x04 */
  367. u32 fmqm_eie; /* Error Interrupt Event Register 0x08 */
  368. u32 fmqm_eien; /* Error Interrupt Enable Register 0x0c */
  369. u32 fmqm_eif; /* Error Interrupt Force Register 0x10 */
  370. u32 fmqm_ie; /* Interrupt Event Register 0x14 */
  371. u32 fmqm_ien; /* Interrupt Enable Register 0x18 */
  372. u32 fmqm_if; /* Interrupt Force Register 0x1c */
  373. u32 fmqm_gs; /* Global Status Register 0x20 */
  374. u32 fmqm_ts; /* Task Status Register 0x24 */
  375. u32 fmqm_etfc; /* Enqueue Total Frame Counter 0x28 */
  376. u32 fmqm_dtfc; /* Dequeue Total Frame Counter 0x2c */
  377. u32 fmqm_dc0; /* Dequeue Counter 0 0x30 */
  378. u32 fmqm_dc1; /* Dequeue Counter 1 0x34 */
  379. u32 fmqm_dc2; /* Dequeue Counter 2 0x38 */
  380. u32 fmqm_dc3; /* Dequeue Counter 3 0x3c */
  381. u32 fmqm_dfdc; /* Dequeue FQID from Default Counter 0x40 */
  382. u32 fmqm_dfcc; /* Dequeue FQID from Context Counter 0x44 */
  383. u32 fmqm_dffc; /* Dequeue FQID from FD Counter 0x48 */
  384. u32 fmqm_dcc; /* Dequeue Confirm Counter 0x4c */
  385. u32 res0050[7]; /* 0x50 - 0x6b */
  386. u32 fmqm_tapc; /* Tnum Aging Period Control 0x6c */
  387. u32 fmqm_dmcvc; /* Dequeue MAC Command Valid Counter 0x70 */
  388. u32 fmqm_difdcc; /* Dequeue Invalid FD Command Counter 0x74 */
  389. u32 fmqm_da1v; /* Dequeue A1 Valid Counter 0x78 */
  390. u32 res007c; /* 0x7c */
  391. u32 fmqm_dtc; /* 0x80 Debug Trap Counter 0x80 */
  392. u32 fmqm_efddd; /* 0x84 Enqueue Frame desc Dynamic dbg 0x84 */
  393. u32 res0088[2]; /* 0x88 - 0x8f */
  394. struct {
  395. u32 fmqm_dtcfg1; /* 0x90 dbg trap cfg 1 Register 0x00 */
  396. u32 fmqm_dtval1; /* Debug Trap Value 1 Register 0x04 */
  397. u32 fmqm_dtm1; /* Debug Trap Mask 1 Register 0x08 */
  398. u32 fmqm_dtc1; /* Debug Trap Counter 1 Register 0x0c */
  399. u32 fmqm_dtcfg2; /* dbg Trap cfg 2 Register 0x10 */
  400. u32 fmqm_dtval2; /* Debug Trap Value 2 Register 0x14 */
  401. u32 fmqm_dtm2; /* Debug Trap Mask 2 Register 0x18 */
  402. u32 res001c; /* 0x1c */
  403. } dbg_traps[3]; /* 0x90 - 0xef */
  404. u8 res00f0[0x400 - 0xf0]; /* 0xf0 - 0x3ff */
  405. };
  406. struct fman_dma_regs {
  407. u32 fmdmsr; /* FM DMA status register 0x00 */
  408. u32 fmdmmr; /* FM DMA mode register 0x04 */
  409. u32 fmdmtr; /* FM DMA bus threshold register 0x08 */
  410. u32 fmdmhy; /* FM DMA bus hysteresis register 0x0c */
  411. u32 fmdmsetr; /* FM DMA SOS emergency Threshold Register 0x10 */
  412. u32 fmdmtah; /* FM DMA transfer bus address high reg 0x14 */
  413. u32 fmdmtal; /* FM DMA transfer bus address low reg 0x18 */
  414. u32 fmdmtcid; /* FM DMA transfer bus communication ID reg 0x1c */
  415. u32 fmdmra; /* FM DMA bus internal ram address register 0x20 */
  416. u32 fmdmrd; /* FM DMA bus internal ram data register 0x24 */
  417. u32 fmdmwcr; /* FM DMA CAM watchdog counter value 0x28 */
  418. u32 fmdmebcr; /* FM DMA CAM base in MURAM register 0x2c */
  419. u32 fmdmccqdr; /* FM DMA CAM and CMD Queue Debug reg 0x30 */
  420. u32 fmdmccqvr1; /* FM DMA CAM and CMD Queue Value reg #1 0x34 */
  421. u32 fmdmccqvr2; /* FM DMA CAM and CMD Queue Value reg #2 0x38 */
  422. u32 fmdmcqvr3; /* FM DMA CMD Queue Value register #3 0x3c */
  423. u32 fmdmcqvr4; /* FM DMA CMD Queue Value register #4 0x40 */
  424. u32 fmdmcqvr5; /* FM DMA CMD Queue Value register #5 0x44 */
  425. u32 fmdmsefrc; /* FM DMA Semaphore Entry Full Reject Cntr 0x48 */
  426. u32 fmdmsqfrc; /* FM DMA Semaphore Queue Full Reject Cntr 0x4c */
  427. u32 fmdmssrc; /* FM DMA Semaphore SYNC Reject Counter 0x50 */
  428. u32 fmdmdcr; /* FM DMA Debug Counter 0x54 */
  429. u32 fmdmemsr; /* FM DMA Emergency Smoother Register 0x58 */
  430. u32 res005c; /* 0x5c */
  431. u32 fmdmplr[FMAN_LIODN_TBL / 2]; /* DMA LIODN regs 0x60-0xdf */
  432. u32 res00e0[0x400 - 56];
  433. };
  434. struct fman_hwp_regs {
  435. u32 res0000[0x844 / 4]; /* 0x000..0x843 */
  436. u32 fmprrpimac; /* FM Parser Internal memory access control */
  437. u32 res[(0x1000 - 0x848) / 4]; /* 0x848..0xFFF */
  438. };
  439. /* Structure that holds current FMan state.
  440. * Used for saving run time information.
  441. */
  442. struct fman_state_struct {
  443. u8 fm_id;
  444. u16 fm_clk_freq;
  445. struct fman_rev_info rev_info;
  446. bool enabled_time_stamp;
  447. u8 count1_micro_bit;
  448. u8 total_num_of_tasks;
  449. u8 accumulated_num_of_tasks;
  450. u32 accumulated_fifo_size;
  451. u8 accumulated_num_of_open_dmas;
  452. u8 accumulated_num_of_deq_tnums;
  453. u32 exceptions;
  454. u32 extra_fifo_pool_size;
  455. u8 extra_tasks_pool_size;
  456. u8 extra_open_dmas_pool_size;
  457. u16 port_mfl[MAX_NUM_OF_MACS];
  458. u16 mac_mfl[MAX_NUM_OF_MACS];
  459. /* SOC specific */
  460. u32 fm_iram_size;
  461. /* DMA */
  462. u32 dma_thresh_max_commq;
  463. u32 dma_thresh_max_buf;
  464. u32 max_num_of_open_dmas;
  465. /* QMI */
  466. u32 qmi_max_num_of_tnums;
  467. u32 qmi_def_tnums_thresh;
  468. /* BMI */
  469. u32 bmi_max_num_of_tasks;
  470. u32 bmi_max_fifo_size;
  471. /* General */
  472. u32 fm_port_num_of_cg;
  473. u32 num_of_rx_ports;
  474. u32 total_fifo_size;
  475. u32 qman_channel_base;
  476. u32 num_of_qman_channels;
  477. struct resource *res;
  478. };
  479. /* Structure that holds FMan initial configuration */
  480. struct fman_cfg {
  481. u8 disp_limit_tsh;
  482. u8 prs_disp_tsh;
  483. u8 plcr_disp_tsh;
  484. u8 kg_disp_tsh;
  485. u8 bmi_disp_tsh;
  486. u8 qmi_enq_disp_tsh;
  487. u8 qmi_deq_disp_tsh;
  488. u8 fm_ctl1_disp_tsh;
  489. u8 fm_ctl2_disp_tsh;
  490. int dma_cache_override;
  491. enum fman_dma_aid_mode dma_aid_mode;
  492. u32 dma_axi_dbg_num_of_beats;
  493. u32 dma_cam_num_of_entries;
  494. u32 dma_watchdog;
  495. u8 dma_comm_qtsh_asrt_emer;
  496. u32 dma_write_buf_tsh_asrt_emer;
  497. u32 dma_read_buf_tsh_asrt_emer;
  498. u8 dma_comm_qtsh_clr_emer;
  499. u32 dma_write_buf_tsh_clr_emer;
  500. u32 dma_read_buf_tsh_clr_emer;
  501. u32 dma_sos_emergency;
  502. int dma_dbg_cnt_mode;
  503. int catastrophic_err;
  504. int dma_err;
  505. u32 exceptions;
  506. u16 clk_freq;
  507. u32 cam_base_addr;
  508. u32 fifo_base_addr;
  509. u32 total_fifo_size;
  510. u32 total_num_of_tasks;
  511. u32 qmi_def_tnums_thresh;
  512. };
  513. #ifdef CONFIG_DPAA_ERRATUM_A050385
  514. static bool fman_has_err_a050385;
  515. #endif
  516. static irqreturn_t fman_exceptions(struct fman *fman,
  517. enum fman_exceptions exception)
  518. {
  519. dev_dbg(fman->dev, "%s: FMan[%d] exception %d\n",
  520. __func__, fman->state->fm_id, exception);
  521. return IRQ_HANDLED;
  522. }
  523. static irqreturn_t fman_bus_error(struct fman *fman, u8 __maybe_unused port_id,
  524. u64 __maybe_unused addr,
  525. u8 __maybe_unused tnum,
  526. u16 __maybe_unused liodn)
  527. {
  528. dev_dbg(fman->dev, "%s: FMan[%d] bus error: port_id[%d]\n",
  529. __func__, fman->state->fm_id, port_id);
  530. return IRQ_HANDLED;
  531. }
  532. static inline irqreturn_t call_mac_isr(struct fman *fman, u8 id)
  533. {
  534. if (fman->intr_mng[id].isr_cb) {
  535. fman->intr_mng[id].isr_cb(fman->intr_mng[id].src_handle);
  536. return IRQ_HANDLED;
  537. }
  538. return IRQ_NONE;
  539. }
  540. static inline u8 hw_port_id_to_sw_port_id(u8 major, u8 hw_port_id)
  541. {
  542. u8 sw_port_id = 0;
  543. if (hw_port_id >= BASE_TX_PORTID)
  544. sw_port_id = hw_port_id - BASE_TX_PORTID;
  545. else if (hw_port_id >= BASE_RX_PORTID)
  546. sw_port_id = hw_port_id - BASE_RX_PORTID;
  547. else
  548. sw_port_id = 0;
  549. return sw_port_id;
  550. }
  551. static void set_port_order_restoration(struct fman_fpm_regs __iomem *fpm_rg,
  552. u8 port_id)
  553. {
  554. u32 tmp = 0;
  555. tmp = port_id << FPM_PORT_FM_CTL_PORTID_SHIFT;
  556. tmp |= FPM_PRT_FM_CTL2 | FPM_PRT_FM_CTL1;
  557. /* order restoration */
  558. if (port_id % 2)
  559. tmp |= FPM_PRT_FM_CTL1 << FPM_PRC_ORA_FM_CTL_SEL_SHIFT;
  560. else
  561. tmp |= FPM_PRT_FM_CTL2 << FPM_PRC_ORA_FM_CTL_SEL_SHIFT;
  562. iowrite32be(tmp, &fpm_rg->fmfp_prc);
  563. }
  564. static void set_port_liodn(struct fman *fman, u8 port_id,
  565. u32 liodn_base, u32 liodn_ofst)
  566. {
  567. u32 tmp;
  568. /* set LIODN base for this port */
  569. tmp = ioread32be(&fman->dma_regs->fmdmplr[port_id / 2]);
  570. if (port_id % 2) {
  571. tmp &= ~DMA_LIODN_BASE_MASK;
  572. tmp |= liodn_base;
  573. } else {
  574. tmp &= ~(DMA_LIODN_BASE_MASK << DMA_LIODN_SHIFT);
  575. tmp |= liodn_base << DMA_LIODN_SHIFT;
  576. }
  577. iowrite32be(tmp, &fman->dma_regs->fmdmplr[port_id / 2]);
  578. iowrite32be(liodn_ofst, &fman->bmi_regs->fmbm_spliodn[port_id - 1]);
  579. }
  580. static void enable_rams_ecc(struct fman_fpm_regs __iomem *fpm_rg)
  581. {
  582. u32 tmp;
  583. tmp = ioread32be(&fpm_rg->fm_rcr);
  584. if (tmp & FPM_RAM_RAMS_ECC_EN_SRC_SEL)
  585. iowrite32be(tmp | FPM_RAM_IRAM_ECC_EN, &fpm_rg->fm_rcr);
  586. else
  587. iowrite32be(tmp | FPM_RAM_RAMS_ECC_EN |
  588. FPM_RAM_IRAM_ECC_EN, &fpm_rg->fm_rcr);
  589. }
  590. static void disable_rams_ecc(struct fman_fpm_regs __iomem *fpm_rg)
  591. {
  592. u32 tmp;
  593. tmp = ioread32be(&fpm_rg->fm_rcr);
  594. if (tmp & FPM_RAM_RAMS_ECC_EN_SRC_SEL)
  595. iowrite32be(tmp & ~FPM_RAM_IRAM_ECC_EN, &fpm_rg->fm_rcr);
  596. else
  597. iowrite32be(tmp & ~(FPM_RAM_RAMS_ECC_EN | FPM_RAM_IRAM_ECC_EN),
  598. &fpm_rg->fm_rcr);
  599. }
  600. static void fman_defconfig(struct fman_cfg *cfg)
  601. {
  602. memset(cfg, 0, sizeof(struct fman_cfg));
  603. cfg->catastrophic_err = DEFAULT_CATASTROPHIC_ERR;
  604. cfg->dma_err = DEFAULT_DMA_ERR;
  605. cfg->dma_aid_mode = DEFAULT_AID_MODE;
  606. cfg->dma_comm_qtsh_clr_emer = DEFAULT_DMA_COMM_Q_LOW;
  607. cfg->dma_comm_qtsh_asrt_emer = DEFAULT_DMA_COMM_Q_HIGH;
  608. cfg->dma_cache_override = DEFAULT_CACHE_OVERRIDE;
  609. cfg->dma_cam_num_of_entries = DEFAULT_DMA_CAM_NUM_OF_ENTRIES;
  610. cfg->dma_dbg_cnt_mode = DEFAULT_DMA_DBG_CNT_MODE;
  611. cfg->dma_sos_emergency = DEFAULT_DMA_SOS_EMERGENCY;
  612. cfg->dma_watchdog = DEFAULT_DMA_WATCHDOG;
  613. cfg->disp_limit_tsh = DEFAULT_DISP_LIMIT;
  614. cfg->prs_disp_tsh = DEFAULT_PRS_DISP_TH;
  615. cfg->plcr_disp_tsh = DEFAULT_PLCR_DISP_TH;
  616. cfg->kg_disp_tsh = DEFAULT_KG_DISP_TH;
  617. cfg->bmi_disp_tsh = DEFAULT_BMI_DISP_TH;
  618. cfg->qmi_enq_disp_tsh = DEFAULT_QMI_ENQ_DISP_TH;
  619. cfg->qmi_deq_disp_tsh = DEFAULT_QMI_DEQ_DISP_TH;
  620. cfg->fm_ctl1_disp_tsh = DEFAULT_FM_CTL1_DISP_TH;
  621. cfg->fm_ctl2_disp_tsh = DEFAULT_FM_CTL2_DISP_TH;
  622. }
  623. static int dma_init(struct fman *fman)
  624. {
  625. struct fman_dma_regs __iomem *dma_rg = fman->dma_regs;
  626. struct fman_cfg *cfg = fman->cfg;
  627. u32 tmp_reg;
  628. /* Init DMA Registers */
  629. /* clear status reg events */
  630. tmp_reg = (DMA_STATUS_BUS_ERR | DMA_STATUS_READ_ECC |
  631. DMA_STATUS_SYSTEM_WRITE_ECC | DMA_STATUS_FM_WRITE_ECC);
  632. iowrite32be(ioread32be(&dma_rg->fmdmsr) | tmp_reg, &dma_rg->fmdmsr);
  633. /* configure mode register */
  634. tmp_reg = 0;
  635. tmp_reg |= cfg->dma_cache_override << DMA_MODE_CACHE_OR_SHIFT;
  636. if (cfg->exceptions & EX_DMA_BUS_ERROR)
  637. tmp_reg |= DMA_MODE_BER;
  638. if ((cfg->exceptions & EX_DMA_SYSTEM_WRITE_ECC) |
  639. (cfg->exceptions & EX_DMA_READ_ECC) |
  640. (cfg->exceptions & EX_DMA_FM_WRITE_ECC))
  641. tmp_reg |= DMA_MODE_ECC;
  642. if (cfg->dma_axi_dbg_num_of_beats)
  643. tmp_reg |= (DMA_MODE_AXI_DBG_MASK &
  644. ((cfg->dma_axi_dbg_num_of_beats - 1)
  645. << DMA_MODE_AXI_DBG_SHIFT));
  646. tmp_reg |= (((cfg->dma_cam_num_of_entries / DMA_CAM_UNITS) - 1) &
  647. DMA_MODE_CEN_MASK) << DMA_MODE_CEN_SHIFT;
  648. tmp_reg |= DMA_MODE_SECURE_PROT;
  649. tmp_reg |= cfg->dma_dbg_cnt_mode << DMA_MODE_DBG_SHIFT;
  650. tmp_reg |= cfg->dma_aid_mode << DMA_MODE_AID_MODE_SHIFT;
  651. iowrite32be(tmp_reg, &dma_rg->fmdmmr);
  652. /* configure thresholds register */
  653. tmp_reg = ((u32)cfg->dma_comm_qtsh_asrt_emer <<
  654. DMA_THRESH_COMMQ_SHIFT);
  655. tmp_reg |= (cfg->dma_read_buf_tsh_asrt_emer &
  656. DMA_THRESH_READ_INT_BUF_MASK) << DMA_THRESH_READ_INT_BUF_SHIFT;
  657. tmp_reg |= cfg->dma_write_buf_tsh_asrt_emer &
  658. DMA_THRESH_WRITE_INT_BUF_MASK;
  659. iowrite32be(tmp_reg, &dma_rg->fmdmtr);
  660. /* configure hysteresis register */
  661. tmp_reg = ((u32)cfg->dma_comm_qtsh_clr_emer <<
  662. DMA_THRESH_COMMQ_SHIFT);
  663. tmp_reg |= (cfg->dma_read_buf_tsh_clr_emer &
  664. DMA_THRESH_READ_INT_BUF_MASK) << DMA_THRESH_READ_INT_BUF_SHIFT;
  665. tmp_reg |= cfg->dma_write_buf_tsh_clr_emer &
  666. DMA_THRESH_WRITE_INT_BUF_MASK;
  667. iowrite32be(tmp_reg, &dma_rg->fmdmhy);
  668. /* configure emergency threshold */
  669. iowrite32be(cfg->dma_sos_emergency, &dma_rg->fmdmsetr);
  670. /* configure Watchdog */
  671. iowrite32be((cfg->dma_watchdog * cfg->clk_freq), &dma_rg->fmdmwcr);
  672. iowrite32be(cfg->cam_base_addr, &dma_rg->fmdmebcr);
  673. /* Allocate MURAM for CAM */
  674. fman->cam_size =
  675. (u32)(fman->cfg->dma_cam_num_of_entries * DMA_CAM_SIZEOF_ENTRY);
  676. fman->cam_offset = fman_muram_alloc(fman->muram, fman->cam_size);
  677. if (IS_ERR_VALUE(fman->cam_offset)) {
  678. dev_err(fman->dev, "%s: MURAM alloc for DMA CAM failed\n",
  679. __func__);
  680. return -ENOMEM;
  681. }
  682. if (fman->state->rev_info.major == 2) {
  683. u32 __iomem *cam_base_addr;
  684. fman_muram_free_mem(fman->muram, fman->cam_offset,
  685. fman->cam_size);
  686. fman->cam_size = fman->cfg->dma_cam_num_of_entries * 72 + 128;
  687. fman->cam_offset = fman_muram_alloc(fman->muram,
  688. fman->cam_size);
  689. if (IS_ERR_VALUE(fman->cam_offset)) {
  690. dev_err(fman->dev, "%s: MURAM alloc for DMA CAM failed\n",
  691. __func__);
  692. return -ENOMEM;
  693. }
  694. if (fman->cfg->dma_cam_num_of_entries % 8 ||
  695. fman->cfg->dma_cam_num_of_entries > 32) {
  696. dev_err(fman->dev, "%s: wrong dma_cam_num_of_entries\n",
  697. __func__);
  698. return -EINVAL;
  699. }
  700. cam_base_addr = (u32 __iomem *)
  701. fman_muram_offset_to_vbase(fman->muram,
  702. fman->cam_offset);
  703. iowrite32be(~((1 <<
  704. (32 - fman->cfg->dma_cam_num_of_entries)) - 1),
  705. cam_base_addr);
  706. }
  707. fman->cfg->cam_base_addr = fman->cam_offset;
  708. return 0;
  709. }
  710. static void fpm_init(struct fman_fpm_regs __iomem *fpm_rg, struct fman_cfg *cfg)
  711. {
  712. u32 tmp_reg;
  713. int i;
  714. /* Init FPM Registers */
  715. tmp_reg = (u32)(cfg->disp_limit_tsh << FPM_DISP_LIMIT_SHIFT);
  716. iowrite32be(tmp_reg, &fpm_rg->fmfp_mxd);
  717. tmp_reg = (((u32)cfg->prs_disp_tsh << FPM_THR1_PRS_SHIFT) |
  718. ((u32)cfg->kg_disp_tsh << FPM_THR1_KG_SHIFT) |
  719. ((u32)cfg->plcr_disp_tsh << FPM_THR1_PLCR_SHIFT) |
  720. ((u32)cfg->bmi_disp_tsh << FPM_THR1_BMI_SHIFT));
  721. iowrite32be(tmp_reg, &fpm_rg->fmfp_dist1);
  722. tmp_reg =
  723. (((u32)cfg->qmi_enq_disp_tsh << FPM_THR2_QMI_ENQ_SHIFT) |
  724. ((u32)cfg->qmi_deq_disp_tsh << FPM_THR2_QMI_DEQ_SHIFT) |
  725. ((u32)cfg->fm_ctl1_disp_tsh << FPM_THR2_FM_CTL1_SHIFT) |
  726. ((u32)cfg->fm_ctl2_disp_tsh << FPM_THR2_FM_CTL2_SHIFT));
  727. iowrite32be(tmp_reg, &fpm_rg->fmfp_dist2);
  728. /* define exceptions and error behavior */
  729. tmp_reg = 0;
  730. /* Clear events */
  731. tmp_reg |= (FPM_EV_MASK_STALL | FPM_EV_MASK_DOUBLE_ECC |
  732. FPM_EV_MASK_SINGLE_ECC);
  733. /* enable interrupts */
  734. if (cfg->exceptions & EX_FPM_STALL_ON_TASKS)
  735. tmp_reg |= FPM_EV_MASK_STALL_EN;
  736. if (cfg->exceptions & EX_FPM_SINGLE_ECC)
  737. tmp_reg |= FPM_EV_MASK_SINGLE_ECC_EN;
  738. if (cfg->exceptions & EX_FPM_DOUBLE_ECC)
  739. tmp_reg |= FPM_EV_MASK_DOUBLE_ECC_EN;
  740. tmp_reg |= (cfg->catastrophic_err << FPM_EV_MASK_CAT_ERR_SHIFT);
  741. tmp_reg |= (cfg->dma_err << FPM_EV_MASK_DMA_ERR_SHIFT);
  742. /* FMan is not halted upon external halt activation */
  743. tmp_reg |= FPM_EV_MASK_EXTERNAL_HALT;
  744. /* Man is not halted upon Unrecoverable ECC error behavior */
  745. tmp_reg |= FPM_EV_MASK_ECC_ERR_HALT;
  746. iowrite32be(tmp_reg, &fpm_rg->fmfp_ee);
  747. /* clear all fmCtls event registers */
  748. for (i = 0; i < FM_NUM_OF_FMAN_CTRL_EVENT_REGS; i++)
  749. iowrite32be(0xFFFFFFFF, &fpm_rg->fmfp_cev[i]);
  750. /* RAM ECC - enable and clear events */
  751. /* first we need to clear all parser memory,
  752. * as it is uninitialized and may cause ECC errors
  753. */
  754. /* event bits */
  755. tmp_reg = (FPM_RAM_MURAM_ECC | FPM_RAM_IRAM_ECC);
  756. iowrite32be(tmp_reg, &fpm_rg->fm_rcr);
  757. tmp_reg = 0;
  758. if (cfg->exceptions & EX_IRAM_ECC) {
  759. tmp_reg |= FPM_IRAM_ECC_ERR_EX_EN;
  760. enable_rams_ecc(fpm_rg);
  761. }
  762. if (cfg->exceptions & EX_MURAM_ECC) {
  763. tmp_reg |= FPM_MURAM_ECC_ERR_EX_EN;
  764. enable_rams_ecc(fpm_rg);
  765. }
  766. iowrite32be(tmp_reg, &fpm_rg->fm_rie);
  767. }
  768. static void bmi_init(struct fman_bmi_regs __iomem *bmi_rg,
  769. struct fman_cfg *cfg)
  770. {
  771. u32 tmp_reg;
  772. /* Init BMI Registers */
  773. /* define common resources */
  774. tmp_reg = cfg->fifo_base_addr;
  775. tmp_reg = tmp_reg / BMI_FIFO_ALIGN;
  776. tmp_reg |= ((cfg->total_fifo_size / FMAN_BMI_FIFO_UNITS - 1) <<
  777. BMI_CFG1_FIFO_SIZE_SHIFT);
  778. iowrite32be(tmp_reg, &bmi_rg->fmbm_cfg1);
  779. tmp_reg = ((cfg->total_num_of_tasks - 1) & BMI_CFG2_TASKS_MASK) <<
  780. BMI_CFG2_TASKS_SHIFT;
  781. /* num of DMA's will be dynamically updated when each port is set */
  782. iowrite32be(tmp_reg, &bmi_rg->fmbm_cfg2);
  783. /* define unmaskable exceptions, enable and clear events */
  784. tmp_reg = 0;
  785. iowrite32be(BMI_ERR_INTR_EN_LIST_RAM_ECC |
  786. BMI_ERR_INTR_EN_STORAGE_PROFILE_ECC |
  787. BMI_ERR_INTR_EN_STATISTICS_RAM_ECC |
  788. BMI_ERR_INTR_EN_DISPATCH_RAM_ECC, &bmi_rg->fmbm_ievr);
  789. if (cfg->exceptions & EX_BMI_LIST_RAM_ECC)
  790. tmp_reg |= BMI_ERR_INTR_EN_LIST_RAM_ECC;
  791. if (cfg->exceptions & EX_BMI_STORAGE_PROFILE_ECC)
  792. tmp_reg |= BMI_ERR_INTR_EN_STORAGE_PROFILE_ECC;
  793. if (cfg->exceptions & EX_BMI_STATISTICS_RAM_ECC)
  794. tmp_reg |= BMI_ERR_INTR_EN_STATISTICS_RAM_ECC;
  795. if (cfg->exceptions & EX_BMI_DISPATCH_RAM_ECC)
  796. tmp_reg |= BMI_ERR_INTR_EN_DISPATCH_RAM_ECC;
  797. iowrite32be(tmp_reg, &bmi_rg->fmbm_ier);
  798. }
  799. static void qmi_init(struct fman_qmi_regs __iomem *qmi_rg,
  800. struct fman_cfg *cfg)
  801. {
  802. u32 tmp_reg;
  803. /* Init QMI Registers */
  804. /* Clear error interrupt events */
  805. iowrite32be(QMI_ERR_INTR_EN_DOUBLE_ECC | QMI_ERR_INTR_EN_DEQ_FROM_DEF,
  806. &qmi_rg->fmqm_eie);
  807. tmp_reg = 0;
  808. if (cfg->exceptions & EX_QMI_DEQ_FROM_UNKNOWN_PORTID)
  809. tmp_reg |= QMI_ERR_INTR_EN_DEQ_FROM_DEF;
  810. if (cfg->exceptions & EX_QMI_DOUBLE_ECC)
  811. tmp_reg |= QMI_ERR_INTR_EN_DOUBLE_ECC;
  812. /* enable events */
  813. iowrite32be(tmp_reg, &qmi_rg->fmqm_eien);
  814. tmp_reg = 0;
  815. /* Clear interrupt events */
  816. iowrite32be(QMI_INTR_EN_SINGLE_ECC, &qmi_rg->fmqm_ie);
  817. if (cfg->exceptions & EX_QMI_SINGLE_ECC)
  818. tmp_reg |= QMI_INTR_EN_SINGLE_ECC;
  819. /* enable events */
  820. iowrite32be(tmp_reg, &qmi_rg->fmqm_ien);
  821. }
  822. static void hwp_init(struct fman_hwp_regs __iomem *hwp_rg)
  823. {
  824. /* enable HW Parser */
  825. iowrite32be(HWP_RPIMAC_PEN, &hwp_rg->fmprrpimac);
  826. }
  827. static int enable(struct fman *fman, struct fman_cfg *cfg)
  828. {
  829. u32 cfg_reg = 0;
  830. /* Enable all modules */
  831. /* clear&enable global counters - calculate reg and save for later,
  832. * because it's the same reg for QMI enable
  833. */
  834. cfg_reg = QMI_CFG_EN_COUNTERS;
  835. /* Set enqueue and dequeue thresholds */
  836. cfg_reg |= (cfg->qmi_def_tnums_thresh << 8) | cfg->qmi_def_tnums_thresh;
  837. iowrite32be(BMI_INIT_START, &fman->bmi_regs->fmbm_init);
  838. iowrite32be(cfg_reg | QMI_CFG_ENQ_EN | QMI_CFG_DEQ_EN,
  839. &fman->qmi_regs->fmqm_gc);
  840. return 0;
  841. }
  842. static int set_exception(struct fman *fman,
  843. enum fman_exceptions exception, bool enable)
  844. {
  845. u32 tmp;
  846. switch (exception) {
  847. case FMAN_EX_DMA_BUS_ERROR:
  848. tmp = ioread32be(&fman->dma_regs->fmdmmr);
  849. if (enable)
  850. tmp |= DMA_MODE_BER;
  851. else
  852. tmp &= ~DMA_MODE_BER;
  853. /* disable bus error */
  854. iowrite32be(tmp, &fman->dma_regs->fmdmmr);
  855. break;
  856. case FMAN_EX_DMA_READ_ECC:
  857. case FMAN_EX_DMA_SYSTEM_WRITE_ECC:
  858. case FMAN_EX_DMA_FM_WRITE_ECC:
  859. tmp = ioread32be(&fman->dma_regs->fmdmmr);
  860. if (enable)
  861. tmp |= DMA_MODE_ECC;
  862. else
  863. tmp &= ~DMA_MODE_ECC;
  864. iowrite32be(tmp, &fman->dma_regs->fmdmmr);
  865. break;
  866. case FMAN_EX_FPM_STALL_ON_TASKS:
  867. tmp = ioread32be(&fman->fpm_regs->fmfp_ee);
  868. if (enable)
  869. tmp |= FPM_EV_MASK_STALL_EN;
  870. else
  871. tmp &= ~FPM_EV_MASK_STALL_EN;
  872. iowrite32be(tmp, &fman->fpm_regs->fmfp_ee);
  873. break;
  874. case FMAN_EX_FPM_SINGLE_ECC:
  875. tmp = ioread32be(&fman->fpm_regs->fmfp_ee);
  876. if (enable)
  877. tmp |= FPM_EV_MASK_SINGLE_ECC_EN;
  878. else
  879. tmp &= ~FPM_EV_MASK_SINGLE_ECC_EN;
  880. iowrite32be(tmp, &fman->fpm_regs->fmfp_ee);
  881. break;
  882. case FMAN_EX_FPM_DOUBLE_ECC:
  883. tmp = ioread32be(&fman->fpm_regs->fmfp_ee);
  884. if (enable)
  885. tmp |= FPM_EV_MASK_DOUBLE_ECC_EN;
  886. else
  887. tmp &= ~FPM_EV_MASK_DOUBLE_ECC_EN;
  888. iowrite32be(tmp, &fman->fpm_regs->fmfp_ee);
  889. break;
  890. case FMAN_EX_QMI_SINGLE_ECC:
  891. tmp = ioread32be(&fman->qmi_regs->fmqm_ien);
  892. if (enable)
  893. tmp |= QMI_INTR_EN_SINGLE_ECC;
  894. else
  895. tmp &= ~QMI_INTR_EN_SINGLE_ECC;
  896. iowrite32be(tmp, &fman->qmi_regs->fmqm_ien);
  897. break;
  898. case FMAN_EX_QMI_DOUBLE_ECC:
  899. tmp = ioread32be(&fman->qmi_regs->fmqm_eien);
  900. if (enable)
  901. tmp |= QMI_ERR_INTR_EN_DOUBLE_ECC;
  902. else
  903. tmp &= ~QMI_ERR_INTR_EN_DOUBLE_ECC;
  904. iowrite32be(tmp, &fman->qmi_regs->fmqm_eien);
  905. break;
  906. case FMAN_EX_QMI_DEQ_FROM_UNKNOWN_PORTID:
  907. tmp = ioread32be(&fman->qmi_regs->fmqm_eien);
  908. if (enable)
  909. tmp |= QMI_ERR_INTR_EN_DEQ_FROM_DEF;
  910. else
  911. tmp &= ~QMI_ERR_INTR_EN_DEQ_FROM_DEF;
  912. iowrite32be(tmp, &fman->qmi_regs->fmqm_eien);
  913. break;
  914. case FMAN_EX_BMI_LIST_RAM_ECC:
  915. tmp = ioread32be(&fman->bmi_regs->fmbm_ier);
  916. if (enable)
  917. tmp |= BMI_ERR_INTR_EN_LIST_RAM_ECC;
  918. else
  919. tmp &= ~BMI_ERR_INTR_EN_LIST_RAM_ECC;
  920. iowrite32be(tmp, &fman->bmi_regs->fmbm_ier);
  921. break;
  922. case FMAN_EX_BMI_STORAGE_PROFILE_ECC:
  923. tmp = ioread32be(&fman->bmi_regs->fmbm_ier);
  924. if (enable)
  925. tmp |= BMI_ERR_INTR_EN_STORAGE_PROFILE_ECC;
  926. else
  927. tmp &= ~BMI_ERR_INTR_EN_STORAGE_PROFILE_ECC;
  928. iowrite32be(tmp, &fman->bmi_regs->fmbm_ier);
  929. break;
  930. case FMAN_EX_BMI_STATISTICS_RAM_ECC:
  931. tmp = ioread32be(&fman->bmi_regs->fmbm_ier);
  932. if (enable)
  933. tmp |= BMI_ERR_INTR_EN_STATISTICS_RAM_ECC;
  934. else
  935. tmp &= ~BMI_ERR_INTR_EN_STATISTICS_RAM_ECC;
  936. iowrite32be(tmp, &fman->bmi_regs->fmbm_ier);
  937. break;
  938. case FMAN_EX_BMI_DISPATCH_RAM_ECC:
  939. tmp = ioread32be(&fman->bmi_regs->fmbm_ier);
  940. if (enable)
  941. tmp |= BMI_ERR_INTR_EN_DISPATCH_RAM_ECC;
  942. else
  943. tmp &= ~BMI_ERR_INTR_EN_DISPATCH_RAM_ECC;
  944. iowrite32be(tmp, &fman->bmi_regs->fmbm_ier);
  945. break;
  946. case FMAN_EX_IRAM_ECC:
  947. tmp = ioread32be(&fman->fpm_regs->fm_rie);
  948. if (enable) {
  949. /* enable ECC if not enabled */
  950. enable_rams_ecc(fman->fpm_regs);
  951. /* enable ECC interrupts */
  952. tmp |= FPM_IRAM_ECC_ERR_EX_EN;
  953. } else {
  954. /* ECC mechanism may be disabled,
  955. * depending on driver status
  956. */
  957. disable_rams_ecc(fman->fpm_regs);
  958. tmp &= ~FPM_IRAM_ECC_ERR_EX_EN;
  959. }
  960. iowrite32be(tmp, &fman->fpm_regs->fm_rie);
  961. break;
  962. case FMAN_EX_MURAM_ECC:
  963. tmp = ioread32be(&fman->fpm_regs->fm_rie);
  964. if (enable) {
  965. /* enable ECC if not enabled */
  966. enable_rams_ecc(fman->fpm_regs);
  967. /* enable ECC interrupts */
  968. tmp |= FPM_MURAM_ECC_ERR_EX_EN;
  969. } else {
  970. /* ECC mechanism may be disabled,
  971. * depending on driver status
  972. */
  973. disable_rams_ecc(fman->fpm_regs);
  974. tmp &= ~FPM_MURAM_ECC_ERR_EX_EN;
  975. }
  976. iowrite32be(tmp, &fman->fpm_regs->fm_rie);
  977. break;
  978. default:
  979. return -EINVAL;
  980. }
  981. return 0;
  982. }
  983. static void resume(struct fman_fpm_regs __iomem *fpm_rg)
  984. {
  985. u32 tmp;
  986. tmp = ioread32be(&fpm_rg->fmfp_ee);
  987. /* clear tmp_reg event bits in order not to clear standing events */
  988. tmp &= ~(FPM_EV_MASK_DOUBLE_ECC |
  989. FPM_EV_MASK_STALL | FPM_EV_MASK_SINGLE_ECC);
  990. tmp |= FPM_EV_MASK_RELEASE_FM;
  991. iowrite32be(tmp, &fpm_rg->fmfp_ee);
  992. }
  993. static int fill_soc_specific_params(struct fman_state_struct *state)
  994. {
  995. u8 minor = state->rev_info.minor;
  996. /* P4080 - Major 2
  997. * P2041/P3041/P5020/P5040 - Major 3
  998. * Tx/Bx - Major 6
  999. */
  1000. switch (state->rev_info.major) {
  1001. case 3:
  1002. state->bmi_max_fifo_size = 160 * 1024;
  1003. state->fm_iram_size = 64 * 1024;
  1004. state->dma_thresh_max_commq = 31;
  1005. state->dma_thresh_max_buf = 127;
  1006. state->qmi_max_num_of_tnums = 64;
  1007. state->qmi_def_tnums_thresh = 48;
  1008. state->bmi_max_num_of_tasks = 128;
  1009. state->max_num_of_open_dmas = 32;
  1010. state->fm_port_num_of_cg = 256;
  1011. state->num_of_rx_ports = 6;
  1012. state->total_fifo_size = 136 * 1024;
  1013. break;
  1014. case 2:
  1015. state->bmi_max_fifo_size = 160 * 1024;
  1016. state->fm_iram_size = 64 * 1024;
  1017. state->dma_thresh_max_commq = 31;
  1018. state->dma_thresh_max_buf = 127;
  1019. state->qmi_max_num_of_tnums = 64;
  1020. state->qmi_def_tnums_thresh = 48;
  1021. state->bmi_max_num_of_tasks = 128;
  1022. state->max_num_of_open_dmas = 32;
  1023. state->fm_port_num_of_cg = 256;
  1024. state->num_of_rx_ports = 5;
  1025. state->total_fifo_size = 100 * 1024;
  1026. break;
  1027. case 6:
  1028. state->dma_thresh_max_commq = 83;
  1029. state->dma_thresh_max_buf = 127;
  1030. state->qmi_max_num_of_tnums = 64;
  1031. state->qmi_def_tnums_thresh = 32;
  1032. state->fm_port_num_of_cg = 256;
  1033. /* FManV3L */
  1034. if (minor == 1 || minor == 4) {
  1035. state->bmi_max_fifo_size = 192 * 1024;
  1036. state->bmi_max_num_of_tasks = 64;
  1037. state->max_num_of_open_dmas = 32;
  1038. state->num_of_rx_ports = 5;
  1039. if (minor == 1)
  1040. state->fm_iram_size = 32 * 1024;
  1041. else
  1042. state->fm_iram_size = 64 * 1024;
  1043. state->total_fifo_size = 156 * 1024;
  1044. }
  1045. /* FManV3H */
  1046. else if (minor == 0 || minor == 2 || minor == 3) {
  1047. state->bmi_max_fifo_size = 384 * 1024;
  1048. state->fm_iram_size = 64 * 1024;
  1049. state->bmi_max_num_of_tasks = 128;
  1050. state->max_num_of_open_dmas = 84;
  1051. state->num_of_rx_ports = 8;
  1052. state->total_fifo_size = 295 * 1024;
  1053. } else {
  1054. pr_err("Unsupported FManv3 version\n");
  1055. return -EINVAL;
  1056. }
  1057. break;
  1058. default:
  1059. pr_err("Unsupported FMan version\n");
  1060. return -EINVAL;
  1061. }
  1062. return 0;
  1063. }
  1064. static bool is_init_done(struct fman_cfg *cfg)
  1065. {
  1066. /* Checks if FMan driver parameters were initialized */
  1067. if (!cfg)
  1068. return true;
  1069. return false;
  1070. }
  1071. static void free_init_resources(struct fman *fman)
  1072. {
  1073. if (fman->cam_offset)
  1074. fman_muram_free_mem(fman->muram, fman->cam_offset,
  1075. fman->cam_size);
  1076. if (fman->fifo_offset)
  1077. fman_muram_free_mem(fman->muram, fman->fifo_offset,
  1078. fman->fifo_size);
  1079. }
  1080. static irqreturn_t bmi_err_event(struct fman *fman)
  1081. {
  1082. u32 event, mask, force;
  1083. struct fman_bmi_regs __iomem *bmi_rg = fman->bmi_regs;
  1084. irqreturn_t ret = IRQ_NONE;
  1085. event = ioread32be(&bmi_rg->fmbm_ievr);
  1086. mask = ioread32be(&bmi_rg->fmbm_ier);
  1087. event &= mask;
  1088. /* clear the forced events */
  1089. force = ioread32be(&bmi_rg->fmbm_ifr);
  1090. if (force & event)
  1091. iowrite32be(force & ~event, &bmi_rg->fmbm_ifr);
  1092. /* clear the acknowledged events */
  1093. iowrite32be(event, &bmi_rg->fmbm_ievr);
  1094. if (event & BMI_ERR_INTR_EN_STORAGE_PROFILE_ECC)
  1095. ret = fman->exception_cb(fman, FMAN_EX_BMI_STORAGE_PROFILE_ECC);
  1096. if (event & BMI_ERR_INTR_EN_LIST_RAM_ECC)
  1097. ret = fman->exception_cb(fman, FMAN_EX_BMI_LIST_RAM_ECC);
  1098. if (event & BMI_ERR_INTR_EN_STATISTICS_RAM_ECC)
  1099. ret = fman->exception_cb(fman, FMAN_EX_BMI_STATISTICS_RAM_ECC);
  1100. if (event & BMI_ERR_INTR_EN_DISPATCH_RAM_ECC)
  1101. ret = fman->exception_cb(fman, FMAN_EX_BMI_DISPATCH_RAM_ECC);
  1102. return ret;
  1103. }
  1104. static irqreturn_t qmi_err_event(struct fman *fman)
  1105. {
  1106. u32 event, mask, force;
  1107. struct fman_qmi_regs __iomem *qmi_rg = fman->qmi_regs;
  1108. irqreturn_t ret = IRQ_NONE;
  1109. event = ioread32be(&qmi_rg->fmqm_eie);
  1110. mask = ioread32be(&qmi_rg->fmqm_eien);
  1111. event &= mask;
  1112. /* clear the forced events */
  1113. force = ioread32be(&qmi_rg->fmqm_eif);
  1114. if (force & event)
  1115. iowrite32be(force & ~event, &qmi_rg->fmqm_eif);
  1116. /* clear the acknowledged events */
  1117. iowrite32be(event, &qmi_rg->fmqm_eie);
  1118. if (event & QMI_ERR_INTR_EN_DOUBLE_ECC)
  1119. ret = fman->exception_cb(fman, FMAN_EX_QMI_DOUBLE_ECC);
  1120. if (event & QMI_ERR_INTR_EN_DEQ_FROM_DEF)
  1121. ret = fman->exception_cb(fman,
  1122. FMAN_EX_QMI_DEQ_FROM_UNKNOWN_PORTID);
  1123. return ret;
  1124. }
  1125. static irqreturn_t dma_err_event(struct fman *fman)
  1126. {
  1127. u32 status, mask, com_id;
  1128. u8 tnum, port_id, relative_port_id;
  1129. u16 liodn;
  1130. struct fman_dma_regs __iomem *dma_rg = fman->dma_regs;
  1131. irqreturn_t ret = IRQ_NONE;
  1132. status = ioread32be(&dma_rg->fmdmsr);
  1133. mask = ioread32be(&dma_rg->fmdmmr);
  1134. /* clear DMA_STATUS_BUS_ERR if mask has no DMA_MODE_BER */
  1135. if ((mask & DMA_MODE_BER) != DMA_MODE_BER)
  1136. status &= ~DMA_STATUS_BUS_ERR;
  1137. /* clear relevant bits if mask has no DMA_MODE_ECC */
  1138. if ((mask & DMA_MODE_ECC) != DMA_MODE_ECC)
  1139. status &= ~(DMA_STATUS_FM_SPDAT_ECC |
  1140. DMA_STATUS_READ_ECC |
  1141. DMA_STATUS_SYSTEM_WRITE_ECC |
  1142. DMA_STATUS_FM_WRITE_ECC);
  1143. /* clear set events */
  1144. iowrite32be(status, &dma_rg->fmdmsr);
  1145. if (status & DMA_STATUS_BUS_ERR) {
  1146. u64 addr;
  1147. addr = (u64)ioread32be(&dma_rg->fmdmtal);
  1148. addr |= ((u64)(ioread32be(&dma_rg->fmdmtah)) << 32);
  1149. com_id = ioread32be(&dma_rg->fmdmtcid);
  1150. port_id = (u8)(((com_id & DMA_TRANSFER_PORTID_MASK) >>
  1151. DMA_TRANSFER_PORTID_SHIFT));
  1152. relative_port_id =
  1153. hw_port_id_to_sw_port_id(fman->state->rev_info.major, port_id);
  1154. tnum = (u8)((com_id & DMA_TRANSFER_TNUM_MASK) >>
  1155. DMA_TRANSFER_TNUM_SHIFT);
  1156. liodn = (u16)(com_id & DMA_TRANSFER_LIODN_MASK);
  1157. ret = fman->bus_error_cb(fman, relative_port_id, addr, tnum,
  1158. liodn);
  1159. }
  1160. if (status & DMA_STATUS_FM_SPDAT_ECC)
  1161. ret = fman->exception_cb(fman, FMAN_EX_DMA_SINGLE_PORT_ECC);
  1162. if (status & DMA_STATUS_READ_ECC)
  1163. ret = fman->exception_cb(fman, FMAN_EX_DMA_READ_ECC);
  1164. if (status & DMA_STATUS_SYSTEM_WRITE_ECC)
  1165. ret = fman->exception_cb(fman, FMAN_EX_DMA_SYSTEM_WRITE_ECC);
  1166. if (status & DMA_STATUS_FM_WRITE_ECC)
  1167. ret = fman->exception_cb(fman, FMAN_EX_DMA_FM_WRITE_ECC);
  1168. return ret;
  1169. }
  1170. static irqreturn_t fpm_err_event(struct fman *fman)
  1171. {
  1172. u32 event;
  1173. struct fman_fpm_regs __iomem *fpm_rg = fman->fpm_regs;
  1174. irqreturn_t ret = IRQ_NONE;
  1175. event = ioread32be(&fpm_rg->fmfp_ee);
  1176. /* clear the all occurred events */
  1177. iowrite32be(event, &fpm_rg->fmfp_ee);
  1178. if ((event & FPM_EV_MASK_DOUBLE_ECC) &&
  1179. (event & FPM_EV_MASK_DOUBLE_ECC_EN))
  1180. ret = fman->exception_cb(fman, FMAN_EX_FPM_DOUBLE_ECC);
  1181. if ((event & FPM_EV_MASK_STALL) && (event & FPM_EV_MASK_STALL_EN))
  1182. ret = fman->exception_cb(fman, FMAN_EX_FPM_STALL_ON_TASKS);
  1183. if ((event & FPM_EV_MASK_SINGLE_ECC) &&
  1184. (event & FPM_EV_MASK_SINGLE_ECC_EN))
  1185. ret = fman->exception_cb(fman, FMAN_EX_FPM_SINGLE_ECC);
  1186. return ret;
  1187. }
  1188. static irqreturn_t muram_err_intr(struct fman *fman)
  1189. {
  1190. u32 event, mask;
  1191. struct fman_fpm_regs __iomem *fpm_rg = fman->fpm_regs;
  1192. irqreturn_t ret = IRQ_NONE;
  1193. event = ioread32be(&fpm_rg->fm_rcr);
  1194. mask = ioread32be(&fpm_rg->fm_rie);
  1195. /* clear MURAM event bit (do not clear IRAM event) */
  1196. iowrite32be(event & ~FPM_RAM_IRAM_ECC, &fpm_rg->fm_rcr);
  1197. if ((mask & FPM_MURAM_ECC_ERR_EX_EN) && (event & FPM_RAM_MURAM_ECC))
  1198. ret = fman->exception_cb(fman, FMAN_EX_MURAM_ECC);
  1199. return ret;
  1200. }
  1201. static irqreturn_t qmi_event(struct fman *fman)
  1202. {
  1203. u32 event, mask, force;
  1204. struct fman_qmi_regs __iomem *qmi_rg = fman->qmi_regs;
  1205. irqreturn_t ret = IRQ_NONE;
  1206. event = ioread32be(&qmi_rg->fmqm_ie);
  1207. mask = ioread32be(&qmi_rg->fmqm_ien);
  1208. event &= mask;
  1209. /* clear the forced events */
  1210. force = ioread32be(&qmi_rg->fmqm_if);
  1211. if (force & event)
  1212. iowrite32be(force & ~event, &qmi_rg->fmqm_if);
  1213. /* clear the acknowledged events */
  1214. iowrite32be(event, &qmi_rg->fmqm_ie);
  1215. if (event & QMI_INTR_EN_SINGLE_ECC)
  1216. ret = fman->exception_cb(fman, FMAN_EX_QMI_SINGLE_ECC);
  1217. return ret;
  1218. }
  1219. static void enable_time_stamp(struct fman *fman)
  1220. {
  1221. struct fman_fpm_regs __iomem *fpm_rg = fman->fpm_regs;
  1222. u16 fm_clk_freq = fman->state->fm_clk_freq;
  1223. u32 tmp, intgr, ts_freq;
  1224. u64 frac;
  1225. ts_freq = (u32)(1 << fman->state->count1_micro_bit);
  1226. /* configure timestamp so that bit 8 will count 1 microsecond
  1227. * Find effective count rate at TIMESTAMP least significant bits:
  1228. * Effective_Count_Rate = 1MHz x 2^8 = 256MHz
  1229. * Find frequency ratio between effective count rate and the clock:
  1230. * Effective_Count_Rate / CLK e.g. for 600 MHz clock:
  1231. * 256/600 = 0.4266666...
  1232. */
  1233. intgr = ts_freq / fm_clk_freq;
  1234. /* we multiply by 2^16 to keep the fraction of the division
  1235. * we do not div back, since we write this value as a fraction
  1236. * see spec
  1237. */
  1238. frac = ((ts_freq << 16) - (intgr << 16) * fm_clk_freq) / fm_clk_freq;
  1239. /* we check remainder of the division in order to round up if not int */
  1240. if (((ts_freq << 16) - (intgr << 16) * fm_clk_freq) % fm_clk_freq)
  1241. frac++;
  1242. tmp = (intgr << FPM_TS_INT_SHIFT) | (u16)frac;
  1243. iowrite32be(tmp, &fpm_rg->fmfp_tsc2);
  1244. /* enable timestamp with original clock */
  1245. iowrite32be(FPM_TS_CTL_EN, &fpm_rg->fmfp_tsc1);
  1246. fman->state->enabled_time_stamp = true;
  1247. }
  1248. static int clear_iram(struct fman *fman)
  1249. {
  1250. struct fman_iram_regs __iomem *iram;
  1251. int i, count;
  1252. iram = fman->base_addr + IMEM_OFFSET;
  1253. /* Enable the auto-increment */
  1254. iowrite32be(IRAM_IADD_AIE, &iram->iadd);
  1255. count = 100;
  1256. do {
  1257. udelay(1);
  1258. } while ((ioread32be(&iram->iadd) != IRAM_IADD_AIE) && --count);
  1259. if (count == 0)
  1260. return -EBUSY;
  1261. for (i = 0; i < (fman->state->fm_iram_size / 4); i++)
  1262. iowrite32be(0xffffffff, &iram->idata);
  1263. iowrite32be(fman->state->fm_iram_size - 4, &iram->iadd);
  1264. count = 100;
  1265. do {
  1266. udelay(1);
  1267. } while ((ioread32be(&iram->idata) != 0xffffffff) && --count);
  1268. if (count == 0)
  1269. return -EBUSY;
  1270. return 0;
  1271. }
  1272. static u32 get_exception_flag(enum fman_exceptions exception)
  1273. {
  1274. u32 bit_mask;
  1275. switch (exception) {
  1276. case FMAN_EX_DMA_BUS_ERROR:
  1277. bit_mask = EX_DMA_BUS_ERROR;
  1278. break;
  1279. case FMAN_EX_DMA_SINGLE_PORT_ECC:
  1280. bit_mask = EX_DMA_SINGLE_PORT_ECC;
  1281. break;
  1282. case FMAN_EX_DMA_READ_ECC:
  1283. bit_mask = EX_DMA_READ_ECC;
  1284. break;
  1285. case FMAN_EX_DMA_SYSTEM_WRITE_ECC:
  1286. bit_mask = EX_DMA_SYSTEM_WRITE_ECC;
  1287. break;
  1288. case FMAN_EX_DMA_FM_WRITE_ECC:
  1289. bit_mask = EX_DMA_FM_WRITE_ECC;
  1290. break;
  1291. case FMAN_EX_FPM_STALL_ON_TASKS:
  1292. bit_mask = EX_FPM_STALL_ON_TASKS;
  1293. break;
  1294. case FMAN_EX_FPM_SINGLE_ECC:
  1295. bit_mask = EX_FPM_SINGLE_ECC;
  1296. break;
  1297. case FMAN_EX_FPM_DOUBLE_ECC:
  1298. bit_mask = EX_FPM_DOUBLE_ECC;
  1299. break;
  1300. case FMAN_EX_QMI_SINGLE_ECC:
  1301. bit_mask = EX_QMI_SINGLE_ECC;
  1302. break;
  1303. case FMAN_EX_QMI_DOUBLE_ECC:
  1304. bit_mask = EX_QMI_DOUBLE_ECC;
  1305. break;
  1306. case FMAN_EX_QMI_DEQ_FROM_UNKNOWN_PORTID:
  1307. bit_mask = EX_QMI_DEQ_FROM_UNKNOWN_PORTID;
  1308. break;
  1309. case FMAN_EX_BMI_LIST_RAM_ECC:
  1310. bit_mask = EX_BMI_LIST_RAM_ECC;
  1311. break;
  1312. case FMAN_EX_BMI_STORAGE_PROFILE_ECC:
  1313. bit_mask = EX_BMI_STORAGE_PROFILE_ECC;
  1314. break;
  1315. case FMAN_EX_BMI_STATISTICS_RAM_ECC:
  1316. bit_mask = EX_BMI_STATISTICS_RAM_ECC;
  1317. break;
  1318. case FMAN_EX_BMI_DISPATCH_RAM_ECC:
  1319. bit_mask = EX_BMI_DISPATCH_RAM_ECC;
  1320. break;
  1321. case FMAN_EX_MURAM_ECC:
  1322. bit_mask = EX_MURAM_ECC;
  1323. break;
  1324. default:
  1325. bit_mask = 0;
  1326. break;
  1327. }
  1328. return bit_mask;
  1329. }
  1330. static int get_module_event(enum fman_event_modules module, u8 mod_id,
  1331. enum fman_intr_type intr_type)
  1332. {
  1333. int event;
  1334. switch (module) {
  1335. case FMAN_MOD_MAC:
  1336. if (intr_type == FMAN_INTR_TYPE_ERR)
  1337. event = FMAN_EV_ERR_MAC0 + mod_id;
  1338. else
  1339. event = FMAN_EV_MAC0 + mod_id;
  1340. break;
  1341. case FMAN_MOD_FMAN_CTRL:
  1342. if (intr_type == FMAN_INTR_TYPE_ERR)
  1343. event = FMAN_EV_CNT;
  1344. else
  1345. event = (FMAN_EV_FMAN_CTRL_0 + mod_id);
  1346. break;
  1347. case FMAN_MOD_DUMMY_LAST:
  1348. event = FMAN_EV_CNT;
  1349. break;
  1350. default:
  1351. event = FMAN_EV_CNT;
  1352. break;
  1353. }
  1354. return event;
  1355. }
  1356. static int set_size_of_fifo(struct fman *fman, u8 port_id, u32 *size_of_fifo,
  1357. u32 *extra_size_of_fifo)
  1358. {
  1359. struct fman_bmi_regs __iomem *bmi_rg = fman->bmi_regs;
  1360. u32 fifo = *size_of_fifo;
  1361. u32 extra_fifo = *extra_size_of_fifo;
  1362. u32 tmp;
  1363. /* if this is the first time a port requires extra_fifo_pool_size,
  1364. * the total extra_fifo_pool_size must be initialized to 1 buffer per
  1365. * port
  1366. */
  1367. if (extra_fifo && !fman->state->extra_fifo_pool_size)
  1368. fman->state->extra_fifo_pool_size =
  1369. fman->state->num_of_rx_ports * FMAN_BMI_FIFO_UNITS;
  1370. fman->state->extra_fifo_pool_size =
  1371. max(fman->state->extra_fifo_pool_size, extra_fifo);
  1372. /* check that there are enough uncommitted fifo size */
  1373. if ((fman->state->accumulated_fifo_size + fifo) >
  1374. (fman->state->total_fifo_size -
  1375. fman->state->extra_fifo_pool_size)) {
  1376. dev_err(fman->dev, "%s: Requested fifo size and extra size exceed total FIFO size.\n",
  1377. __func__);
  1378. return -EAGAIN;
  1379. }
  1380. /* Read, modify and write to HW */
  1381. tmp = (fifo / FMAN_BMI_FIFO_UNITS - 1) |
  1382. ((extra_fifo / FMAN_BMI_FIFO_UNITS) <<
  1383. BMI_EXTRA_FIFO_SIZE_SHIFT);
  1384. iowrite32be(tmp, &bmi_rg->fmbm_pfs[port_id - 1]);
  1385. /* update accumulated */
  1386. fman->state->accumulated_fifo_size += fifo;
  1387. return 0;
  1388. }
  1389. static int set_num_of_tasks(struct fman *fman, u8 port_id, u8 *num_of_tasks,
  1390. u8 *num_of_extra_tasks)
  1391. {
  1392. struct fman_bmi_regs __iomem *bmi_rg = fman->bmi_regs;
  1393. u8 tasks = *num_of_tasks;
  1394. u8 extra_tasks = *num_of_extra_tasks;
  1395. u32 tmp;
  1396. if (extra_tasks)
  1397. fman->state->extra_tasks_pool_size =
  1398. max(fman->state->extra_tasks_pool_size, extra_tasks);
  1399. /* check that there are enough uncommitted tasks */
  1400. if ((fman->state->accumulated_num_of_tasks + tasks) >
  1401. (fman->state->total_num_of_tasks -
  1402. fman->state->extra_tasks_pool_size)) {
  1403. dev_err(fman->dev, "%s: Requested num_of_tasks and extra tasks pool for fm%d exceed total num_of_tasks.\n",
  1404. __func__, fman->state->fm_id);
  1405. return -EAGAIN;
  1406. }
  1407. /* update accumulated */
  1408. fman->state->accumulated_num_of_tasks += tasks;
  1409. /* Write to HW */
  1410. tmp = ioread32be(&bmi_rg->fmbm_pp[port_id - 1]) &
  1411. ~(BMI_NUM_OF_TASKS_MASK | BMI_NUM_OF_EXTRA_TASKS_MASK);
  1412. tmp |= ((u32)((tasks - 1) << BMI_NUM_OF_TASKS_SHIFT) |
  1413. (u32)(extra_tasks << BMI_EXTRA_NUM_OF_TASKS_SHIFT));
  1414. iowrite32be(tmp, &bmi_rg->fmbm_pp[port_id - 1]);
  1415. return 0;
  1416. }
  1417. static int set_num_of_open_dmas(struct fman *fman, u8 port_id,
  1418. u8 *num_of_open_dmas,
  1419. u8 *num_of_extra_open_dmas)
  1420. {
  1421. struct fman_bmi_regs __iomem *bmi_rg = fman->bmi_regs;
  1422. u8 open_dmas = *num_of_open_dmas;
  1423. u8 extra_open_dmas = *num_of_extra_open_dmas;
  1424. u8 total_num_dmas = 0, current_val = 0, current_extra_val = 0;
  1425. u32 tmp;
  1426. if (!open_dmas) {
  1427. /* Configuration according to values in the HW.
  1428. * read the current number of open Dma's
  1429. */
  1430. tmp = ioread32be(&bmi_rg->fmbm_pp[port_id - 1]);
  1431. current_extra_val = (u8)((tmp & BMI_NUM_OF_EXTRA_DMAS_MASK) >>
  1432. BMI_EXTRA_NUM_OF_DMAS_SHIFT);
  1433. tmp = ioread32be(&bmi_rg->fmbm_pp[port_id - 1]);
  1434. current_val = (u8)(((tmp & BMI_NUM_OF_DMAS_MASK) >>
  1435. BMI_NUM_OF_DMAS_SHIFT) + 1);
  1436. /* This is the first configuration and user did not
  1437. * specify value (!open_dmas), reset values will be used
  1438. * and we just save these values for resource management
  1439. */
  1440. fman->state->extra_open_dmas_pool_size =
  1441. (u8)max(fman->state->extra_open_dmas_pool_size,
  1442. current_extra_val);
  1443. fman->state->accumulated_num_of_open_dmas += current_val;
  1444. *num_of_open_dmas = current_val;
  1445. *num_of_extra_open_dmas = current_extra_val;
  1446. return 0;
  1447. }
  1448. if (extra_open_dmas > current_extra_val)
  1449. fman->state->extra_open_dmas_pool_size =
  1450. (u8)max(fman->state->extra_open_dmas_pool_size,
  1451. extra_open_dmas);
  1452. if ((fman->state->rev_info.major < 6) &&
  1453. (fman->state->accumulated_num_of_open_dmas - current_val +
  1454. open_dmas > fman->state->max_num_of_open_dmas)) {
  1455. dev_err(fman->dev, "%s: Requested num_of_open_dmas for fm%d exceeds total num_of_open_dmas.\n",
  1456. __func__, fman->state->fm_id);
  1457. return -EAGAIN;
  1458. } else if ((fman->state->rev_info.major >= 6) &&
  1459. !((fman->state->rev_info.major == 6) &&
  1460. (fman->state->rev_info.minor == 0)) &&
  1461. (fman->state->accumulated_num_of_open_dmas -
  1462. current_val + open_dmas >
  1463. fman->state->dma_thresh_max_commq + 1)) {
  1464. dev_err(fman->dev, "%s: Requested num_of_open_dmas for fm%d exceeds DMA Command queue (%d)\n",
  1465. __func__, fman->state->fm_id,
  1466. fman->state->dma_thresh_max_commq + 1);
  1467. return -EAGAIN;
  1468. }
  1469. WARN_ON(fman->state->accumulated_num_of_open_dmas < current_val);
  1470. /* update acummulated */
  1471. fman->state->accumulated_num_of_open_dmas -= current_val;
  1472. fman->state->accumulated_num_of_open_dmas += open_dmas;
  1473. if (fman->state->rev_info.major < 6)
  1474. total_num_dmas =
  1475. (u8)(fman->state->accumulated_num_of_open_dmas +
  1476. fman->state->extra_open_dmas_pool_size);
  1477. /* calculate reg */
  1478. tmp = ioread32be(&bmi_rg->fmbm_pp[port_id - 1]) &
  1479. ~(BMI_NUM_OF_DMAS_MASK | BMI_NUM_OF_EXTRA_DMAS_MASK);
  1480. tmp |= (u32)(((open_dmas - 1) << BMI_NUM_OF_DMAS_SHIFT) |
  1481. (extra_open_dmas << BMI_EXTRA_NUM_OF_DMAS_SHIFT));
  1482. iowrite32be(tmp, &bmi_rg->fmbm_pp[port_id - 1]);
  1483. /* update total num of DMA's with committed number of open DMAS,
  1484. * and max uncommitted pool.
  1485. */
  1486. if (total_num_dmas) {
  1487. tmp = ioread32be(&bmi_rg->fmbm_cfg2) & ~BMI_CFG2_DMAS_MASK;
  1488. tmp |= (u32)(total_num_dmas - 1) << BMI_CFG2_DMAS_SHIFT;
  1489. iowrite32be(tmp, &bmi_rg->fmbm_cfg2);
  1490. }
  1491. return 0;
  1492. }
  1493. static int fman_config(struct fman *fman)
  1494. {
  1495. void __iomem *base_addr;
  1496. int err;
  1497. base_addr = fman->dts_params.base_addr;
  1498. fman->state = kzalloc(sizeof(*fman->state), GFP_KERNEL);
  1499. if (!fman->state)
  1500. goto err_fm_state;
  1501. /* Allocate the FM driver's parameters structure */
  1502. fman->cfg = kzalloc(sizeof(*fman->cfg), GFP_KERNEL);
  1503. if (!fman->cfg)
  1504. goto err_fm_drv;
  1505. /* Initialize MURAM block */
  1506. fman->muram =
  1507. fman_muram_init(fman->dts_params.muram_res.start,
  1508. resource_size(&fman->dts_params.muram_res));
  1509. if (!fman->muram)
  1510. goto err_fm_soc_specific;
  1511. /* Initialize FM parameters which will be kept by the driver */
  1512. fman->state->fm_id = fman->dts_params.id;
  1513. fman->state->fm_clk_freq = fman->dts_params.clk_freq;
  1514. fman->state->qman_channel_base = fman->dts_params.qman_channel_base;
  1515. fman->state->num_of_qman_channels =
  1516. fman->dts_params.num_of_qman_channels;
  1517. fman->state->res = fman->dts_params.res;
  1518. fman->exception_cb = fman_exceptions;
  1519. fman->bus_error_cb = fman_bus_error;
  1520. fman->fpm_regs = base_addr + FPM_OFFSET;
  1521. fman->bmi_regs = base_addr + BMI_OFFSET;
  1522. fman->qmi_regs = base_addr + QMI_OFFSET;
  1523. fman->dma_regs = base_addr + DMA_OFFSET;
  1524. fman->hwp_regs = base_addr + HWP_OFFSET;
  1525. fman->kg_regs = base_addr + KG_OFFSET;
  1526. fman->base_addr = base_addr;
  1527. spin_lock_init(&fman->spinlock);
  1528. fman_defconfig(fman->cfg);
  1529. fman->state->extra_fifo_pool_size = 0;
  1530. fman->state->exceptions = (EX_DMA_BUS_ERROR |
  1531. EX_DMA_READ_ECC |
  1532. EX_DMA_SYSTEM_WRITE_ECC |
  1533. EX_DMA_FM_WRITE_ECC |
  1534. EX_FPM_STALL_ON_TASKS |
  1535. EX_FPM_SINGLE_ECC |
  1536. EX_FPM_DOUBLE_ECC |
  1537. EX_QMI_DEQ_FROM_UNKNOWN_PORTID |
  1538. EX_BMI_LIST_RAM_ECC |
  1539. EX_BMI_STORAGE_PROFILE_ECC |
  1540. EX_BMI_STATISTICS_RAM_ECC |
  1541. EX_MURAM_ECC |
  1542. EX_BMI_DISPATCH_RAM_ECC |
  1543. EX_QMI_DOUBLE_ECC |
  1544. EX_QMI_SINGLE_ECC);
  1545. /* Read FMan revision for future use*/
  1546. fman_get_revision(fman, &fman->state->rev_info);
  1547. err = fill_soc_specific_params(fman->state);
  1548. if (err)
  1549. goto err_fm_soc_specific;
  1550. /* FM_AID_MODE_NO_TNUM_SW005 Errata workaround */
  1551. if (fman->state->rev_info.major >= 6)
  1552. fman->cfg->dma_aid_mode = FMAN_DMA_AID_OUT_PORT_ID;
  1553. fman->cfg->qmi_def_tnums_thresh = fman->state->qmi_def_tnums_thresh;
  1554. fman->state->total_num_of_tasks =
  1555. (u8)DFLT_TOTAL_NUM_OF_TASKS(fman->state->rev_info.major,
  1556. fman->state->rev_info.minor,
  1557. fman->state->bmi_max_num_of_tasks);
  1558. if (fman->state->rev_info.major < 6) {
  1559. fman->cfg->dma_comm_qtsh_clr_emer =
  1560. (u8)DFLT_DMA_COMM_Q_LOW(fman->state->rev_info.major,
  1561. fman->state->dma_thresh_max_commq);
  1562. fman->cfg->dma_comm_qtsh_asrt_emer =
  1563. (u8)DFLT_DMA_COMM_Q_HIGH(fman->state->rev_info.major,
  1564. fman->state->dma_thresh_max_commq);
  1565. fman->cfg->dma_cam_num_of_entries =
  1566. DFLT_DMA_CAM_NUM_OF_ENTRIES(fman->state->rev_info.major);
  1567. fman->cfg->dma_read_buf_tsh_clr_emer =
  1568. DFLT_DMA_READ_INT_BUF_LOW(fman->state->dma_thresh_max_buf);
  1569. fman->cfg->dma_read_buf_tsh_asrt_emer =
  1570. DFLT_DMA_READ_INT_BUF_HIGH(fman->state->dma_thresh_max_buf);
  1571. fman->cfg->dma_write_buf_tsh_clr_emer =
  1572. DFLT_DMA_WRITE_INT_BUF_LOW(fman->state->dma_thresh_max_buf);
  1573. fman->cfg->dma_write_buf_tsh_asrt_emer =
  1574. DFLT_DMA_WRITE_INT_BUF_HIGH(fman->state->dma_thresh_max_buf);
  1575. fman->cfg->dma_axi_dbg_num_of_beats =
  1576. DFLT_AXI_DBG_NUM_OF_BEATS;
  1577. }
  1578. return 0;
  1579. err_fm_soc_specific:
  1580. kfree(fman->cfg);
  1581. err_fm_drv:
  1582. kfree(fman->state);
  1583. err_fm_state:
  1584. kfree(fman);
  1585. return -EINVAL;
  1586. }
  1587. static int fman_reset(struct fman *fman)
  1588. {
  1589. u32 count;
  1590. int err = 0;
  1591. if (fman->state->rev_info.major < 6) {
  1592. iowrite32be(FPM_RSTC_FM_RESET, &fman->fpm_regs->fm_rstc);
  1593. /* Wait for reset completion */
  1594. count = 100;
  1595. do {
  1596. udelay(1);
  1597. } while (((ioread32be(&fman->fpm_regs->fm_rstc)) &
  1598. FPM_RSTC_FM_RESET) && --count);
  1599. if (count == 0)
  1600. err = -EBUSY;
  1601. goto _return;
  1602. } else {
  1603. #ifdef CONFIG_PPC
  1604. struct device_node *guts_node;
  1605. struct ccsr_guts __iomem *guts_regs;
  1606. u32 devdisr2, reg;
  1607. /* Errata A007273 */
  1608. guts_node =
  1609. of_find_compatible_node(NULL, NULL,
  1610. "fsl,qoriq-device-config-2.0");
  1611. if (!guts_node) {
  1612. dev_err(fman->dev, "%s: Couldn't find guts node\n",
  1613. __func__);
  1614. goto guts_node;
  1615. }
  1616. guts_regs = of_iomap(guts_node, 0);
  1617. if (!guts_regs) {
  1618. dev_err(fman->dev, "%s: Couldn't map %pOF regs\n",
  1619. __func__, guts_node);
  1620. goto guts_regs;
  1621. }
  1622. #define FMAN1_ALL_MACS_MASK 0xFCC00000
  1623. #define FMAN2_ALL_MACS_MASK 0x000FCC00
  1624. /* Read current state */
  1625. devdisr2 = ioread32be(&guts_regs->devdisr2);
  1626. if (fman->dts_params.id == 0)
  1627. reg = devdisr2 & ~FMAN1_ALL_MACS_MASK;
  1628. else
  1629. reg = devdisr2 & ~FMAN2_ALL_MACS_MASK;
  1630. /* Enable all MACs */
  1631. iowrite32be(reg, &guts_regs->devdisr2);
  1632. #endif
  1633. /* Perform FMan reset */
  1634. iowrite32be(FPM_RSTC_FM_RESET, &fman->fpm_regs->fm_rstc);
  1635. /* Wait for reset completion */
  1636. count = 100;
  1637. do {
  1638. udelay(1);
  1639. } while (((ioread32be(&fman->fpm_regs->fm_rstc)) &
  1640. FPM_RSTC_FM_RESET) && --count);
  1641. if (count == 0) {
  1642. #ifdef CONFIG_PPC
  1643. iounmap(guts_regs);
  1644. of_node_put(guts_node);
  1645. #endif
  1646. err = -EBUSY;
  1647. goto _return;
  1648. }
  1649. #ifdef CONFIG_PPC
  1650. /* Restore devdisr2 value */
  1651. iowrite32be(devdisr2, &guts_regs->devdisr2);
  1652. iounmap(guts_regs);
  1653. of_node_put(guts_node);
  1654. #endif
  1655. goto _return;
  1656. #ifdef CONFIG_PPC
  1657. guts_regs:
  1658. of_node_put(guts_node);
  1659. guts_node:
  1660. dev_dbg(fman->dev, "%s: Didn't perform FManV3 reset due to Errata A007273!\n",
  1661. __func__);
  1662. #endif
  1663. }
  1664. _return:
  1665. return err;
  1666. }
  1667. static int fman_init(struct fman *fman)
  1668. {
  1669. struct fman_cfg *cfg = NULL;
  1670. int err = 0, i, count;
  1671. if (is_init_done(fman->cfg))
  1672. return -EINVAL;
  1673. fman->state->count1_micro_bit = FM_TIMESTAMP_1_USEC_BIT;
  1674. cfg = fman->cfg;
  1675. /* clear revision-dependent non existing exception */
  1676. if (fman->state->rev_info.major < 6)
  1677. fman->state->exceptions &= ~FMAN_EX_BMI_DISPATCH_RAM_ECC;
  1678. if (fman->state->rev_info.major >= 6)
  1679. fman->state->exceptions &= ~FMAN_EX_QMI_SINGLE_ECC;
  1680. /* clear CPG */
  1681. memset_io((void __iomem *)(fman->base_addr + CGP_OFFSET), 0,
  1682. fman->state->fm_port_num_of_cg);
  1683. /* Save LIODN info before FMan reset
  1684. * Skipping non-existent port 0 (i = 1)
  1685. */
  1686. for (i = 1; i < FMAN_LIODN_TBL; i++) {
  1687. u32 liodn_base;
  1688. fman->liodn_offset[i] =
  1689. ioread32be(&fman->bmi_regs->fmbm_spliodn[i - 1]);
  1690. liodn_base = ioread32be(&fman->dma_regs->fmdmplr[i / 2]);
  1691. if (i % 2) {
  1692. /* FMDM_PLR LSB holds LIODN base for odd ports */
  1693. liodn_base &= DMA_LIODN_BASE_MASK;
  1694. } else {
  1695. /* FMDM_PLR MSB holds LIODN base for even ports */
  1696. liodn_base >>= DMA_LIODN_SHIFT;
  1697. liodn_base &= DMA_LIODN_BASE_MASK;
  1698. }
  1699. fman->liodn_base[i] = liodn_base;
  1700. }
  1701. err = fman_reset(fman);
  1702. if (err)
  1703. return err;
  1704. if (ioread32be(&fman->qmi_regs->fmqm_gs) & QMI_GS_HALT_NOT_BUSY) {
  1705. resume(fman->fpm_regs);
  1706. /* Wait until QMI is not in halt not busy state */
  1707. count = 100;
  1708. do {
  1709. udelay(1);
  1710. } while (((ioread32be(&fman->qmi_regs->fmqm_gs)) &
  1711. QMI_GS_HALT_NOT_BUSY) && --count);
  1712. if (count == 0)
  1713. dev_warn(fman->dev, "%s: QMI is in halt not busy state\n",
  1714. __func__);
  1715. }
  1716. if (clear_iram(fman) != 0)
  1717. return -EINVAL;
  1718. cfg->exceptions = fman->state->exceptions;
  1719. /* Init DMA Registers */
  1720. err = dma_init(fman);
  1721. if (err != 0) {
  1722. free_init_resources(fman);
  1723. return err;
  1724. }
  1725. /* Init FPM Registers */
  1726. fpm_init(fman->fpm_regs, fman->cfg);
  1727. /* define common resources */
  1728. /* allocate MURAM for FIFO according to total size */
  1729. fman->fifo_offset = fman_muram_alloc(fman->muram,
  1730. fman->state->total_fifo_size);
  1731. if (IS_ERR_VALUE(fman->fifo_offset)) {
  1732. free_init_resources(fman);
  1733. dev_err(fman->dev, "%s: MURAM alloc for BMI FIFO failed\n",
  1734. __func__);
  1735. return -ENOMEM;
  1736. }
  1737. cfg->fifo_base_addr = fman->fifo_offset;
  1738. cfg->total_fifo_size = fman->state->total_fifo_size;
  1739. cfg->total_num_of_tasks = fman->state->total_num_of_tasks;
  1740. cfg->clk_freq = fman->state->fm_clk_freq;
  1741. /* Init BMI Registers */
  1742. bmi_init(fman->bmi_regs, fman->cfg);
  1743. /* Init QMI Registers */
  1744. qmi_init(fman->qmi_regs, fman->cfg);
  1745. /* Init HW Parser */
  1746. hwp_init(fman->hwp_regs);
  1747. /* Init KeyGen */
  1748. fman->keygen = keygen_init(fman->kg_regs);
  1749. if (!fman->keygen)
  1750. return -EINVAL;
  1751. err = enable(fman, cfg);
  1752. if (err != 0)
  1753. return err;
  1754. enable_time_stamp(fman);
  1755. kfree(fman->cfg);
  1756. fman->cfg = NULL;
  1757. return 0;
  1758. }
  1759. static int fman_set_exception(struct fman *fman,
  1760. enum fman_exceptions exception, bool enable)
  1761. {
  1762. u32 bit_mask = 0;
  1763. if (!is_init_done(fman->cfg))
  1764. return -EINVAL;
  1765. bit_mask = get_exception_flag(exception);
  1766. if (bit_mask) {
  1767. if (enable)
  1768. fman->state->exceptions |= bit_mask;
  1769. else
  1770. fman->state->exceptions &= ~bit_mask;
  1771. } else {
  1772. dev_err(fman->dev, "%s: Undefined exception (%d)\n",
  1773. __func__, exception);
  1774. return -EINVAL;
  1775. }
  1776. return set_exception(fman, exception, enable);
  1777. }
  1778. /**
  1779. * fman_register_intr
  1780. * @fman: A Pointer to FMan device
  1781. * @mod: Calling module
  1782. * @mod_id: Module id (if more than 1 exists, '0' if not)
  1783. * @intr_type: Interrupt type (error/normal) selection.
  1784. * @f_isr: The interrupt service routine.
  1785. * @h_src_arg: Argument to be passed to f_isr.
  1786. *
  1787. * Used to register an event handler to be processed by FMan
  1788. *
  1789. * Return: 0 on success; Error code otherwise.
  1790. */
  1791. void fman_register_intr(struct fman *fman, enum fman_event_modules module,
  1792. u8 mod_id, enum fman_intr_type intr_type,
  1793. void (*isr_cb)(void *src_arg), void *src_arg)
  1794. {
  1795. int event = 0;
  1796. event = get_module_event(module, mod_id, intr_type);
  1797. WARN_ON(event >= FMAN_EV_CNT);
  1798. /* register in local FM structure */
  1799. fman->intr_mng[event].isr_cb = isr_cb;
  1800. fman->intr_mng[event].src_handle = src_arg;
  1801. }
  1802. EXPORT_SYMBOL(fman_register_intr);
  1803. /**
  1804. * fman_unregister_intr
  1805. * @fman: A Pointer to FMan device
  1806. * @mod: Calling module
  1807. * @mod_id: Module id (if more than 1 exists, '0' if not)
  1808. * @intr_type: Interrupt type (error/normal) selection.
  1809. *
  1810. * Used to unregister an event handler to be processed by FMan
  1811. *
  1812. * Return: 0 on success; Error code otherwise.
  1813. */
  1814. void fman_unregister_intr(struct fman *fman, enum fman_event_modules module,
  1815. u8 mod_id, enum fman_intr_type intr_type)
  1816. {
  1817. int event = 0;
  1818. event = get_module_event(module, mod_id, intr_type);
  1819. WARN_ON(event >= FMAN_EV_CNT);
  1820. fman->intr_mng[event].isr_cb = NULL;
  1821. fman->intr_mng[event].src_handle = NULL;
  1822. }
  1823. EXPORT_SYMBOL(fman_unregister_intr);
  1824. /**
  1825. * fman_set_port_params
  1826. * @fman: A Pointer to FMan device
  1827. * @port_params: Port parameters
  1828. *
  1829. * Used by FMan Port to pass parameters to the FMan
  1830. *
  1831. * Return: 0 on success; Error code otherwise.
  1832. */
  1833. int fman_set_port_params(struct fman *fman,
  1834. struct fman_port_init_params *port_params)
  1835. {
  1836. int err;
  1837. unsigned long flags;
  1838. u8 port_id = port_params->port_id, mac_id;
  1839. spin_lock_irqsave(&fman->spinlock, flags);
  1840. err = set_num_of_tasks(fman, port_params->port_id,
  1841. &port_params->num_of_tasks,
  1842. &port_params->num_of_extra_tasks);
  1843. if (err)
  1844. goto return_err;
  1845. /* TX Ports */
  1846. if (port_params->port_type != FMAN_PORT_TYPE_RX) {
  1847. u32 enq_th, deq_th, reg;
  1848. /* update qmi ENQ/DEQ threshold */
  1849. fman->state->accumulated_num_of_deq_tnums +=
  1850. port_params->deq_pipeline_depth;
  1851. enq_th = (ioread32be(&fman->qmi_regs->fmqm_gc) &
  1852. QMI_CFG_ENQ_MASK) >> QMI_CFG_ENQ_SHIFT;
  1853. /* if enq_th is too big, we reduce it to the max value
  1854. * that is still 0
  1855. */
  1856. if (enq_th >= (fman->state->qmi_max_num_of_tnums -
  1857. fman->state->accumulated_num_of_deq_tnums)) {
  1858. enq_th =
  1859. fman->state->qmi_max_num_of_tnums -
  1860. fman->state->accumulated_num_of_deq_tnums - 1;
  1861. reg = ioread32be(&fman->qmi_regs->fmqm_gc);
  1862. reg &= ~QMI_CFG_ENQ_MASK;
  1863. reg |= (enq_th << QMI_CFG_ENQ_SHIFT);
  1864. iowrite32be(reg, &fman->qmi_regs->fmqm_gc);
  1865. }
  1866. deq_th = ioread32be(&fman->qmi_regs->fmqm_gc) &
  1867. QMI_CFG_DEQ_MASK;
  1868. /* if deq_th is too small, we enlarge it to the min
  1869. * value that is still 0.
  1870. * depTh may not be larger than 63
  1871. * (fman->state->qmi_max_num_of_tnums-1).
  1872. */
  1873. if ((deq_th <= fman->state->accumulated_num_of_deq_tnums) &&
  1874. (deq_th < fman->state->qmi_max_num_of_tnums - 1)) {
  1875. deq_th = fman->state->accumulated_num_of_deq_tnums + 1;
  1876. reg = ioread32be(&fman->qmi_regs->fmqm_gc);
  1877. reg &= ~QMI_CFG_DEQ_MASK;
  1878. reg |= deq_th;
  1879. iowrite32be(reg, &fman->qmi_regs->fmqm_gc);
  1880. }
  1881. }
  1882. err = set_size_of_fifo(fman, port_params->port_id,
  1883. &port_params->size_of_fifo,
  1884. &port_params->extra_size_of_fifo);
  1885. if (err)
  1886. goto return_err;
  1887. err = set_num_of_open_dmas(fman, port_params->port_id,
  1888. &port_params->num_of_open_dmas,
  1889. &port_params->num_of_extra_open_dmas);
  1890. if (err)
  1891. goto return_err;
  1892. set_port_liodn(fman, port_id, fman->liodn_base[port_id],
  1893. fman->liodn_offset[port_id]);
  1894. if (fman->state->rev_info.major < 6)
  1895. set_port_order_restoration(fman->fpm_regs, port_id);
  1896. mac_id = hw_port_id_to_sw_port_id(fman->state->rev_info.major, port_id);
  1897. if (port_params->max_frame_length >= fman->state->mac_mfl[mac_id]) {
  1898. fman->state->port_mfl[mac_id] = port_params->max_frame_length;
  1899. } else {
  1900. dev_warn(fman->dev, "%s: Port (%d) max_frame_length is smaller than MAC (%d) current MTU\n",
  1901. __func__, port_id, mac_id);
  1902. err = -EINVAL;
  1903. goto return_err;
  1904. }
  1905. spin_unlock_irqrestore(&fman->spinlock, flags);
  1906. return 0;
  1907. return_err:
  1908. spin_unlock_irqrestore(&fman->spinlock, flags);
  1909. return err;
  1910. }
  1911. EXPORT_SYMBOL(fman_set_port_params);
  1912. /**
  1913. * fman_reset_mac
  1914. * @fman: A Pointer to FMan device
  1915. * @mac_id: MAC id to be reset
  1916. *
  1917. * Reset a specific MAC
  1918. *
  1919. * Return: 0 on success; Error code otherwise.
  1920. */
  1921. int fman_reset_mac(struct fman *fman, u8 mac_id)
  1922. {
  1923. struct fman_fpm_regs __iomem *fpm_rg = fman->fpm_regs;
  1924. u32 msk, timeout = 100;
  1925. if (fman->state->rev_info.major >= 6) {
  1926. dev_err(fman->dev, "%s: FMan MAC reset no available for FMan V3!\n",
  1927. __func__);
  1928. return -EINVAL;
  1929. }
  1930. /* Get the relevant bit mask */
  1931. switch (mac_id) {
  1932. case 0:
  1933. msk = FPM_RSTC_MAC0_RESET;
  1934. break;
  1935. case 1:
  1936. msk = FPM_RSTC_MAC1_RESET;
  1937. break;
  1938. case 2:
  1939. msk = FPM_RSTC_MAC2_RESET;
  1940. break;
  1941. case 3:
  1942. msk = FPM_RSTC_MAC3_RESET;
  1943. break;
  1944. case 4:
  1945. msk = FPM_RSTC_MAC4_RESET;
  1946. break;
  1947. case 5:
  1948. msk = FPM_RSTC_MAC5_RESET;
  1949. break;
  1950. case 6:
  1951. msk = FPM_RSTC_MAC6_RESET;
  1952. break;
  1953. case 7:
  1954. msk = FPM_RSTC_MAC7_RESET;
  1955. break;
  1956. case 8:
  1957. msk = FPM_RSTC_MAC8_RESET;
  1958. break;
  1959. case 9:
  1960. msk = FPM_RSTC_MAC9_RESET;
  1961. break;
  1962. default:
  1963. dev_warn(fman->dev, "%s: Illegal MAC Id [%d]\n",
  1964. __func__, mac_id);
  1965. return -EINVAL;
  1966. }
  1967. /* reset */
  1968. iowrite32be(msk, &fpm_rg->fm_rstc);
  1969. while ((ioread32be(&fpm_rg->fm_rstc) & msk) && --timeout)
  1970. udelay(10);
  1971. if (!timeout)
  1972. return -EIO;
  1973. return 0;
  1974. }
  1975. EXPORT_SYMBOL(fman_reset_mac);
  1976. /**
  1977. * fman_set_mac_max_frame
  1978. * @fman: A Pointer to FMan device
  1979. * @mac_id: MAC id
  1980. * @mfl: Maximum frame length
  1981. *
  1982. * Set maximum frame length of specific MAC in FMan driver
  1983. *
  1984. * Return: 0 on success; Error code otherwise.
  1985. */
  1986. int fman_set_mac_max_frame(struct fman *fman, u8 mac_id, u16 mfl)
  1987. {
  1988. /* if port is already initialized, check that MaxFrameLength is smaller
  1989. * or equal to the port's max
  1990. */
  1991. if ((!fman->state->port_mfl[mac_id]) ||
  1992. (mfl <= fman->state->port_mfl[mac_id])) {
  1993. fman->state->mac_mfl[mac_id] = mfl;
  1994. } else {
  1995. dev_warn(fman->dev, "%s: MAC max_frame_length is larger than Port max_frame_length\n",
  1996. __func__);
  1997. return -EINVAL;
  1998. }
  1999. return 0;
  2000. }
  2001. EXPORT_SYMBOL(fman_set_mac_max_frame);
  2002. /**
  2003. * fman_get_clock_freq
  2004. * @fman: A Pointer to FMan device
  2005. *
  2006. * Get FMan clock frequency
  2007. *
  2008. * Return: FMan clock frequency
  2009. */
  2010. u16 fman_get_clock_freq(struct fman *fman)
  2011. {
  2012. return fman->state->fm_clk_freq;
  2013. }
  2014. /**
  2015. * fman_get_bmi_max_fifo_size
  2016. * @fman: A Pointer to FMan device
  2017. *
  2018. * Get FMan maximum FIFO size
  2019. *
  2020. * Return: FMan Maximum FIFO size
  2021. */
  2022. u32 fman_get_bmi_max_fifo_size(struct fman *fman)
  2023. {
  2024. return fman->state->bmi_max_fifo_size;
  2025. }
  2026. EXPORT_SYMBOL(fman_get_bmi_max_fifo_size);
  2027. /**
  2028. * fman_get_revision
  2029. * @fman - Pointer to the FMan module
  2030. * @rev_info - A structure of revision information parameters.
  2031. *
  2032. * Returns the FM revision
  2033. *
  2034. * Allowed only following fman_init().
  2035. *
  2036. * Return: 0 on success; Error code otherwise.
  2037. */
  2038. void fman_get_revision(struct fman *fman, struct fman_rev_info *rev_info)
  2039. {
  2040. u32 tmp;
  2041. tmp = ioread32be(&fman->fpm_regs->fm_ip_rev_1);
  2042. rev_info->major = (u8)((tmp & FPM_REV1_MAJOR_MASK) >>
  2043. FPM_REV1_MAJOR_SHIFT);
  2044. rev_info->minor = tmp & FPM_REV1_MINOR_MASK;
  2045. }
  2046. EXPORT_SYMBOL(fman_get_revision);
  2047. /**
  2048. * fman_get_qman_channel_id
  2049. * @fman: A Pointer to FMan device
  2050. * @port_id: Port id
  2051. *
  2052. * Get QMan channel ID associated to the Port id
  2053. *
  2054. * Return: QMan channel ID
  2055. */
  2056. u32 fman_get_qman_channel_id(struct fman *fman, u32 port_id)
  2057. {
  2058. int i;
  2059. if (fman->state->rev_info.major >= 6) {
  2060. static const u32 port_ids[] = {
  2061. 0x30, 0x31, 0x28, 0x29, 0x2a, 0x2b,
  2062. 0x2c, 0x2d, 0x2, 0x3, 0x4, 0x5, 0x7, 0x7
  2063. };
  2064. for (i = 0; i < fman->state->num_of_qman_channels; i++) {
  2065. if (port_ids[i] == port_id)
  2066. break;
  2067. }
  2068. } else {
  2069. static const u32 port_ids[] = {
  2070. 0x30, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x1,
  2071. 0x2, 0x3, 0x4, 0x5, 0x7, 0x7
  2072. };
  2073. for (i = 0; i < fman->state->num_of_qman_channels; i++) {
  2074. if (port_ids[i] == port_id)
  2075. break;
  2076. }
  2077. }
  2078. if (i == fman->state->num_of_qman_channels)
  2079. return 0;
  2080. return fman->state->qman_channel_base + i;
  2081. }
  2082. EXPORT_SYMBOL(fman_get_qman_channel_id);
  2083. /**
  2084. * fman_get_mem_region
  2085. * @fman: A Pointer to FMan device
  2086. *
  2087. * Get FMan memory region
  2088. *
  2089. * Return: A structure with FMan memory region information
  2090. */
  2091. struct resource *fman_get_mem_region(struct fman *fman)
  2092. {
  2093. return fman->state->res;
  2094. }
  2095. EXPORT_SYMBOL(fman_get_mem_region);
  2096. /* Bootargs defines */
  2097. /* Extra headroom for RX buffers - Default, min and max */
  2098. #define FSL_FM_RX_EXTRA_HEADROOM 64
  2099. #define FSL_FM_RX_EXTRA_HEADROOM_MIN 16
  2100. #define FSL_FM_RX_EXTRA_HEADROOM_MAX 384
  2101. /* Maximum frame length */
  2102. #define FSL_FM_MAX_FRAME_SIZE 1522
  2103. #define FSL_FM_MAX_POSSIBLE_FRAME_SIZE 9600
  2104. #define FSL_FM_MIN_POSSIBLE_FRAME_SIZE 64
  2105. /* Extra headroom for Rx buffers.
  2106. * FMan is instructed to allocate, on the Rx path, this amount of
  2107. * space at the beginning of a data buffer, beside the DPA private
  2108. * data area and the IC fields.
  2109. * Does not impact Tx buffer layout.
  2110. * Configurable from bootargs. 64 by default, it's needed on
  2111. * particular forwarding scenarios that add extra headers to the
  2112. * forwarded frame.
  2113. */
  2114. static int fsl_fm_rx_extra_headroom = FSL_FM_RX_EXTRA_HEADROOM;
  2115. module_param(fsl_fm_rx_extra_headroom, int, 0);
  2116. MODULE_PARM_DESC(fsl_fm_rx_extra_headroom, "Extra headroom for Rx buffers");
  2117. /* Max frame size, across all interfaces.
  2118. * Configurable from bootargs, to avoid allocating oversized (socket)
  2119. * buffers when not using jumbo frames.
  2120. * Must be large enough to accommodate the network MTU, but small enough
  2121. * to avoid wasting skb memory.
  2122. *
  2123. * Could be overridden once, at boot-time, via the
  2124. * fm_set_max_frm() callback.
  2125. */
  2126. static int fsl_fm_max_frm = FSL_FM_MAX_FRAME_SIZE;
  2127. module_param(fsl_fm_max_frm, int, 0);
  2128. MODULE_PARM_DESC(fsl_fm_max_frm, "Maximum frame size, across all interfaces");
  2129. /**
  2130. * fman_get_max_frm
  2131. *
  2132. * Return: Max frame length configured in the FM driver
  2133. */
  2134. u16 fman_get_max_frm(void)
  2135. {
  2136. static bool fm_check_mfl;
  2137. if (!fm_check_mfl) {
  2138. if (fsl_fm_max_frm > FSL_FM_MAX_POSSIBLE_FRAME_SIZE ||
  2139. fsl_fm_max_frm < FSL_FM_MIN_POSSIBLE_FRAME_SIZE) {
  2140. pr_warn("Invalid fsl_fm_max_frm value (%d) in bootargs, valid range is %d-%d. Falling back to the default (%d)\n",
  2141. fsl_fm_max_frm,
  2142. FSL_FM_MIN_POSSIBLE_FRAME_SIZE,
  2143. FSL_FM_MAX_POSSIBLE_FRAME_SIZE,
  2144. FSL_FM_MAX_FRAME_SIZE);
  2145. fsl_fm_max_frm = FSL_FM_MAX_FRAME_SIZE;
  2146. }
  2147. fm_check_mfl = true;
  2148. }
  2149. return fsl_fm_max_frm;
  2150. }
  2151. EXPORT_SYMBOL(fman_get_max_frm);
  2152. /**
  2153. * fman_get_rx_extra_headroom
  2154. *
  2155. * Return: Extra headroom size configured in the FM driver
  2156. */
  2157. int fman_get_rx_extra_headroom(void)
  2158. {
  2159. static bool fm_check_rx_extra_headroom;
  2160. if (!fm_check_rx_extra_headroom) {
  2161. if (fsl_fm_rx_extra_headroom > FSL_FM_RX_EXTRA_HEADROOM_MAX ||
  2162. fsl_fm_rx_extra_headroom < FSL_FM_RX_EXTRA_HEADROOM_MIN) {
  2163. pr_warn("Invalid fsl_fm_rx_extra_headroom value (%d) in bootargs, valid range is %d-%d. Falling back to the default (%d)\n",
  2164. fsl_fm_rx_extra_headroom,
  2165. FSL_FM_RX_EXTRA_HEADROOM_MIN,
  2166. FSL_FM_RX_EXTRA_HEADROOM_MAX,
  2167. FSL_FM_RX_EXTRA_HEADROOM);
  2168. fsl_fm_rx_extra_headroom = FSL_FM_RX_EXTRA_HEADROOM;
  2169. }
  2170. fm_check_rx_extra_headroom = true;
  2171. fsl_fm_rx_extra_headroom = ALIGN(fsl_fm_rx_extra_headroom, 16);
  2172. }
  2173. return fsl_fm_rx_extra_headroom;
  2174. }
  2175. EXPORT_SYMBOL(fman_get_rx_extra_headroom);
  2176. /**
  2177. * fman_bind
  2178. * @dev: FMan OF device pointer
  2179. *
  2180. * Bind to a specific FMan device.
  2181. *
  2182. * Allowed only after the port was created.
  2183. *
  2184. * Return: A pointer to the FMan device
  2185. */
  2186. struct fman *fman_bind(struct device *fm_dev)
  2187. {
  2188. return (struct fman *)(dev_get_drvdata(get_device(fm_dev)));
  2189. }
  2190. EXPORT_SYMBOL(fman_bind);
  2191. #ifdef CONFIG_DPAA_ERRATUM_A050385
  2192. bool fman_has_errata_a050385(void)
  2193. {
  2194. return fman_has_err_a050385;
  2195. }
  2196. EXPORT_SYMBOL(fman_has_errata_a050385);
  2197. #endif
  2198. static irqreturn_t fman_err_irq(int irq, void *handle)
  2199. {
  2200. struct fman *fman = (struct fman *)handle;
  2201. u32 pending;
  2202. struct fman_fpm_regs __iomem *fpm_rg;
  2203. irqreturn_t single_ret, ret = IRQ_NONE;
  2204. if (!is_init_done(fman->cfg))
  2205. return IRQ_NONE;
  2206. fpm_rg = fman->fpm_regs;
  2207. /* error interrupts */
  2208. pending = ioread32be(&fpm_rg->fm_epi);
  2209. if (!pending)
  2210. return IRQ_NONE;
  2211. if (pending & ERR_INTR_EN_BMI) {
  2212. single_ret = bmi_err_event(fman);
  2213. if (single_ret == IRQ_HANDLED)
  2214. ret = IRQ_HANDLED;
  2215. }
  2216. if (pending & ERR_INTR_EN_QMI) {
  2217. single_ret = qmi_err_event(fman);
  2218. if (single_ret == IRQ_HANDLED)
  2219. ret = IRQ_HANDLED;
  2220. }
  2221. if (pending & ERR_INTR_EN_FPM) {
  2222. single_ret = fpm_err_event(fman);
  2223. if (single_ret == IRQ_HANDLED)
  2224. ret = IRQ_HANDLED;
  2225. }
  2226. if (pending & ERR_INTR_EN_DMA) {
  2227. single_ret = dma_err_event(fman);
  2228. if (single_ret == IRQ_HANDLED)
  2229. ret = IRQ_HANDLED;
  2230. }
  2231. if (pending & ERR_INTR_EN_MURAM) {
  2232. single_ret = muram_err_intr(fman);
  2233. if (single_ret == IRQ_HANDLED)
  2234. ret = IRQ_HANDLED;
  2235. }
  2236. /* MAC error interrupts */
  2237. if (pending & ERR_INTR_EN_MAC0) {
  2238. single_ret = call_mac_isr(fman, FMAN_EV_ERR_MAC0 + 0);
  2239. if (single_ret == IRQ_HANDLED)
  2240. ret = IRQ_HANDLED;
  2241. }
  2242. if (pending & ERR_INTR_EN_MAC1) {
  2243. single_ret = call_mac_isr(fman, FMAN_EV_ERR_MAC0 + 1);
  2244. if (single_ret == IRQ_HANDLED)
  2245. ret = IRQ_HANDLED;
  2246. }
  2247. if (pending & ERR_INTR_EN_MAC2) {
  2248. single_ret = call_mac_isr(fman, FMAN_EV_ERR_MAC0 + 2);
  2249. if (single_ret == IRQ_HANDLED)
  2250. ret = IRQ_HANDLED;
  2251. }
  2252. if (pending & ERR_INTR_EN_MAC3) {
  2253. single_ret = call_mac_isr(fman, FMAN_EV_ERR_MAC0 + 3);
  2254. if (single_ret == IRQ_HANDLED)
  2255. ret = IRQ_HANDLED;
  2256. }
  2257. if (pending & ERR_INTR_EN_MAC4) {
  2258. single_ret = call_mac_isr(fman, FMAN_EV_ERR_MAC0 + 4);
  2259. if (single_ret == IRQ_HANDLED)
  2260. ret = IRQ_HANDLED;
  2261. }
  2262. if (pending & ERR_INTR_EN_MAC5) {
  2263. single_ret = call_mac_isr(fman, FMAN_EV_ERR_MAC0 + 5);
  2264. if (single_ret == IRQ_HANDLED)
  2265. ret = IRQ_HANDLED;
  2266. }
  2267. if (pending & ERR_INTR_EN_MAC6) {
  2268. single_ret = call_mac_isr(fman, FMAN_EV_ERR_MAC0 + 6);
  2269. if (single_ret == IRQ_HANDLED)
  2270. ret = IRQ_HANDLED;
  2271. }
  2272. if (pending & ERR_INTR_EN_MAC7) {
  2273. single_ret = call_mac_isr(fman, FMAN_EV_ERR_MAC0 + 7);
  2274. if (single_ret == IRQ_HANDLED)
  2275. ret = IRQ_HANDLED;
  2276. }
  2277. if (pending & ERR_INTR_EN_MAC8) {
  2278. single_ret = call_mac_isr(fman, FMAN_EV_ERR_MAC0 + 8);
  2279. if (single_ret == IRQ_HANDLED)
  2280. ret = IRQ_HANDLED;
  2281. }
  2282. if (pending & ERR_INTR_EN_MAC9) {
  2283. single_ret = call_mac_isr(fman, FMAN_EV_ERR_MAC0 + 9);
  2284. if (single_ret == IRQ_HANDLED)
  2285. ret = IRQ_HANDLED;
  2286. }
  2287. return ret;
  2288. }
  2289. static irqreturn_t fman_irq(int irq, void *handle)
  2290. {
  2291. struct fman *fman = (struct fman *)handle;
  2292. u32 pending;
  2293. struct fman_fpm_regs __iomem *fpm_rg;
  2294. irqreturn_t single_ret, ret = IRQ_NONE;
  2295. if (!is_init_done(fman->cfg))
  2296. return IRQ_NONE;
  2297. fpm_rg = fman->fpm_regs;
  2298. /* normal interrupts */
  2299. pending = ioread32be(&fpm_rg->fm_npi);
  2300. if (!pending)
  2301. return IRQ_NONE;
  2302. if (pending & INTR_EN_QMI) {
  2303. single_ret = qmi_event(fman);
  2304. if (single_ret == IRQ_HANDLED)
  2305. ret = IRQ_HANDLED;
  2306. }
  2307. /* MAC interrupts */
  2308. if (pending & INTR_EN_MAC0) {
  2309. single_ret = call_mac_isr(fman, FMAN_EV_MAC0 + 0);
  2310. if (single_ret == IRQ_HANDLED)
  2311. ret = IRQ_HANDLED;
  2312. }
  2313. if (pending & INTR_EN_MAC1) {
  2314. single_ret = call_mac_isr(fman, FMAN_EV_MAC0 + 1);
  2315. if (single_ret == IRQ_HANDLED)
  2316. ret = IRQ_HANDLED;
  2317. }
  2318. if (pending & INTR_EN_MAC2) {
  2319. single_ret = call_mac_isr(fman, FMAN_EV_MAC0 + 2);
  2320. if (single_ret == IRQ_HANDLED)
  2321. ret = IRQ_HANDLED;
  2322. }
  2323. if (pending & INTR_EN_MAC3) {
  2324. single_ret = call_mac_isr(fman, FMAN_EV_MAC0 + 3);
  2325. if (single_ret == IRQ_HANDLED)
  2326. ret = IRQ_HANDLED;
  2327. }
  2328. if (pending & INTR_EN_MAC4) {
  2329. single_ret = call_mac_isr(fman, FMAN_EV_MAC0 + 4);
  2330. if (single_ret == IRQ_HANDLED)
  2331. ret = IRQ_HANDLED;
  2332. }
  2333. if (pending & INTR_EN_MAC5) {
  2334. single_ret = call_mac_isr(fman, FMAN_EV_MAC0 + 5);
  2335. if (single_ret == IRQ_HANDLED)
  2336. ret = IRQ_HANDLED;
  2337. }
  2338. if (pending & INTR_EN_MAC6) {
  2339. single_ret = call_mac_isr(fman, FMAN_EV_MAC0 + 6);
  2340. if (single_ret == IRQ_HANDLED)
  2341. ret = IRQ_HANDLED;
  2342. }
  2343. if (pending & INTR_EN_MAC7) {
  2344. single_ret = call_mac_isr(fman, FMAN_EV_MAC0 + 7);
  2345. if (single_ret == IRQ_HANDLED)
  2346. ret = IRQ_HANDLED;
  2347. }
  2348. if (pending & INTR_EN_MAC8) {
  2349. single_ret = call_mac_isr(fman, FMAN_EV_MAC0 + 8);
  2350. if (single_ret == IRQ_HANDLED)
  2351. ret = IRQ_HANDLED;
  2352. }
  2353. if (pending & INTR_EN_MAC9) {
  2354. single_ret = call_mac_isr(fman, FMAN_EV_MAC0 + 9);
  2355. if (single_ret == IRQ_HANDLED)
  2356. ret = IRQ_HANDLED;
  2357. }
  2358. return ret;
  2359. }
  2360. static const struct of_device_id fman_muram_match[] = {
  2361. {
  2362. .compatible = "fsl,fman-muram"},
  2363. {}
  2364. };
  2365. MODULE_DEVICE_TABLE(of, fman_muram_match);
  2366. static struct fman *read_dts_node(struct platform_device *of_dev)
  2367. {
  2368. struct fman *fman;
  2369. struct device_node *fm_node, *muram_node;
  2370. struct resource *res;
  2371. u32 val, range[2];
  2372. int err, irq;
  2373. struct clk *clk;
  2374. u32 clk_rate;
  2375. phys_addr_t phys_base_addr;
  2376. resource_size_t mem_size;
  2377. fman = kzalloc(sizeof(*fman), GFP_KERNEL);
  2378. if (!fman)
  2379. return NULL;
  2380. fm_node = of_node_get(of_dev->dev.of_node);
  2381. err = of_property_read_u32(fm_node, "cell-index", &val);
  2382. if (err) {
  2383. dev_err(&of_dev->dev, "%s: failed to read cell-index for %pOF\n",
  2384. __func__, fm_node);
  2385. goto fman_node_put;
  2386. }
  2387. fman->dts_params.id = (u8)val;
  2388. /* Get the FM interrupt */
  2389. res = platform_get_resource(of_dev, IORESOURCE_IRQ, 0);
  2390. if (!res) {
  2391. dev_err(&of_dev->dev, "%s: Can't get FMan IRQ resource\n",
  2392. __func__);
  2393. goto fman_node_put;
  2394. }
  2395. irq = res->start;
  2396. /* Get the FM error interrupt */
  2397. res = platform_get_resource(of_dev, IORESOURCE_IRQ, 1);
  2398. if (!res) {
  2399. dev_err(&of_dev->dev, "%s: Can't get FMan Error IRQ resource\n",
  2400. __func__);
  2401. goto fman_node_put;
  2402. }
  2403. fman->dts_params.err_irq = res->start;
  2404. /* Get the FM address */
  2405. res = platform_get_resource(of_dev, IORESOURCE_MEM, 0);
  2406. if (!res) {
  2407. dev_err(&of_dev->dev, "%s: Can't get FMan memory resource\n",
  2408. __func__);
  2409. goto fman_node_put;
  2410. }
  2411. phys_base_addr = res->start;
  2412. mem_size = resource_size(res);
  2413. clk = of_clk_get(fm_node, 0);
  2414. if (IS_ERR(clk)) {
  2415. dev_err(&of_dev->dev, "%s: Failed to get FM%d clock structure\n",
  2416. __func__, fman->dts_params.id);
  2417. goto fman_node_put;
  2418. }
  2419. clk_rate = clk_get_rate(clk);
  2420. if (!clk_rate) {
  2421. dev_err(&of_dev->dev, "%s: Failed to determine FM%d clock rate\n",
  2422. __func__, fman->dts_params.id);
  2423. goto fman_node_put;
  2424. }
  2425. /* Rounding to MHz */
  2426. fman->dts_params.clk_freq = DIV_ROUND_UP(clk_rate, 1000000);
  2427. err = of_property_read_u32_array(fm_node, "fsl,qman-channel-range",
  2428. &range[0], 2);
  2429. if (err) {
  2430. dev_err(&of_dev->dev, "%s: failed to read fsl,qman-channel-range for %pOF\n",
  2431. __func__, fm_node);
  2432. goto fman_node_put;
  2433. }
  2434. fman->dts_params.qman_channel_base = range[0];
  2435. fman->dts_params.num_of_qman_channels = range[1];
  2436. /* Get the MURAM base address and size */
  2437. muram_node = of_find_matching_node(fm_node, fman_muram_match);
  2438. if (!muram_node) {
  2439. dev_err(&of_dev->dev, "%s: could not find MURAM node\n",
  2440. __func__);
  2441. goto fman_free;
  2442. }
  2443. err = of_address_to_resource(muram_node, 0,
  2444. &fman->dts_params.muram_res);
  2445. if (err) {
  2446. of_node_put(muram_node);
  2447. dev_err(&of_dev->dev, "%s: of_address_to_resource() = %d\n",
  2448. __func__, err);
  2449. goto fman_free;
  2450. }
  2451. of_node_put(muram_node);
  2452. err = devm_request_irq(&of_dev->dev, irq, fman_irq, IRQF_SHARED,
  2453. "fman", fman);
  2454. if (err < 0) {
  2455. dev_err(&of_dev->dev, "%s: irq %d allocation failed (error = %d)\n",
  2456. __func__, irq, err);
  2457. goto fman_free;
  2458. }
  2459. if (fman->dts_params.err_irq != 0) {
  2460. err = devm_request_irq(&of_dev->dev, fman->dts_params.err_irq,
  2461. fman_err_irq, IRQF_SHARED,
  2462. "fman-err", fman);
  2463. if (err < 0) {
  2464. dev_err(&of_dev->dev, "%s: irq %d allocation failed (error = %d)\n",
  2465. __func__, fman->dts_params.err_irq, err);
  2466. goto fman_free;
  2467. }
  2468. }
  2469. fman->dts_params.res =
  2470. devm_request_mem_region(&of_dev->dev, phys_base_addr,
  2471. mem_size, "fman");
  2472. if (!fman->dts_params.res) {
  2473. dev_err(&of_dev->dev, "%s: request_mem_region() failed\n",
  2474. __func__);
  2475. goto fman_free;
  2476. }
  2477. fman->dts_params.base_addr =
  2478. devm_ioremap(&of_dev->dev, phys_base_addr, mem_size);
  2479. if (!fman->dts_params.base_addr) {
  2480. dev_err(&of_dev->dev, "%s: devm_ioremap() failed\n", __func__);
  2481. goto fman_free;
  2482. }
  2483. fman->dev = &of_dev->dev;
  2484. err = of_platform_populate(fm_node, NULL, NULL, &of_dev->dev);
  2485. if (err) {
  2486. dev_err(&of_dev->dev, "%s: of_platform_populate() failed\n",
  2487. __func__);
  2488. goto fman_free;
  2489. }
  2490. #ifdef CONFIG_DPAA_ERRATUM_A050385
  2491. fman_has_err_a050385 =
  2492. of_property_read_bool(fm_node, "fsl,erratum-a050385");
  2493. #endif
  2494. return fman;
  2495. fman_node_put:
  2496. of_node_put(fm_node);
  2497. fman_free:
  2498. kfree(fman);
  2499. return NULL;
  2500. }
  2501. static int fman_probe(struct platform_device *of_dev)
  2502. {
  2503. struct fman *fman;
  2504. struct device *dev;
  2505. int err;
  2506. dev = &of_dev->dev;
  2507. fman = read_dts_node(of_dev);
  2508. if (!fman)
  2509. return -EIO;
  2510. err = fman_config(fman);
  2511. if (err) {
  2512. dev_err(dev, "%s: FMan config failed\n", __func__);
  2513. return -EINVAL;
  2514. }
  2515. if (fman_init(fman) != 0) {
  2516. dev_err(dev, "%s: FMan init failed\n", __func__);
  2517. return -EINVAL;
  2518. }
  2519. if (fman->dts_params.err_irq == 0) {
  2520. fman_set_exception(fman, FMAN_EX_DMA_BUS_ERROR, false);
  2521. fman_set_exception(fman, FMAN_EX_DMA_READ_ECC, false);
  2522. fman_set_exception(fman, FMAN_EX_DMA_SYSTEM_WRITE_ECC, false);
  2523. fman_set_exception(fman, FMAN_EX_DMA_FM_WRITE_ECC, false);
  2524. fman_set_exception(fman, FMAN_EX_DMA_SINGLE_PORT_ECC, false);
  2525. fman_set_exception(fman, FMAN_EX_FPM_STALL_ON_TASKS, false);
  2526. fman_set_exception(fman, FMAN_EX_FPM_SINGLE_ECC, false);
  2527. fman_set_exception(fman, FMAN_EX_FPM_DOUBLE_ECC, false);
  2528. fman_set_exception(fman, FMAN_EX_QMI_SINGLE_ECC, false);
  2529. fman_set_exception(fman, FMAN_EX_QMI_DOUBLE_ECC, false);
  2530. fman_set_exception(fman,
  2531. FMAN_EX_QMI_DEQ_FROM_UNKNOWN_PORTID, false);
  2532. fman_set_exception(fman, FMAN_EX_BMI_LIST_RAM_ECC, false);
  2533. fman_set_exception(fman, FMAN_EX_BMI_STORAGE_PROFILE_ECC,
  2534. false);
  2535. fman_set_exception(fman, FMAN_EX_BMI_STATISTICS_RAM_ECC, false);
  2536. fman_set_exception(fman, FMAN_EX_BMI_DISPATCH_RAM_ECC, false);
  2537. }
  2538. dev_set_drvdata(dev, fman);
  2539. dev_dbg(dev, "FMan%d probed\n", fman->dts_params.id);
  2540. return 0;
  2541. }
  2542. static const struct of_device_id fman_match[] = {
  2543. {
  2544. .compatible = "fsl,fman"},
  2545. {}
  2546. };
  2547. MODULE_DEVICE_TABLE(of, fman_match);
  2548. static struct platform_driver fman_driver = {
  2549. .driver = {
  2550. .name = "fsl-fman",
  2551. .of_match_table = fman_match,
  2552. },
  2553. .probe = fman_probe,
  2554. };
  2555. static int __init fman_load(void)
  2556. {
  2557. int err;
  2558. pr_debug("FSL DPAA FMan driver\n");
  2559. err = platform_driver_register(&fman_driver);
  2560. if (err < 0)
  2561. pr_err("Error, platform_driver_register() = %d\n", err);
  2562. return err;
  2563. }
  2564. module_init(fman_load);
  2565. static void __exit fman_unload(void)
  2566. {
  2567. platform_driver_unregister(&fman_driver);
  2568. }
  2569. module_exit(fman_unload);
  2570. MODULE_LICENSE("Dual BSD/GPL");
  2571. MODULE_DESCRIPTION("Freescale DPAA Frame Manager driver");