vxge-traffic.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476
  1. /******************************************************************************
  2. * This software may be used and distributed according to the terms of
  3. * the GNU General Public License (GPL), incorporated herein by reference.
  4. * Drivers based on or derived from this code fall under the GPL and must
  5. * retain the authorship, copyright and license notice. This file is not
  6. * a complete program and may only be used when the entire operating
  7. * system is licensed under the GPL.
  8. * See the file COPYING in this distribution for more information.
  9. *
  10. * vxge-traffic.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
  11. * Virtualized Server Adapter.
  12. * Copyright(c) 2002-2010 Exar Corp.
  13. ******************************************************************************/
  14. #include <linux/etherdevice.h>
  15. #include <linux/prefetch.h>
  16. #include "vxge-traffic.h"
  17. #include "vxge-config.h"
  18. #include "vxge-main.h"
  19. /*
  20. * vxge_hw_vpath_intr_enable - Enable vpath interrupts.
  21. * @vp: Virtual Path handle.
  22. *
  23. * Enable vpath interrupts. The function is to be executed the last in
  24. * vpath initialization sequence.
  25. *
  26. * See also: vxge_hw_vpath_intr_disable()
  27. */
  28. enum vxge_hw_status vxge_hw_vpath_intr_enable(struct __vxge_hw_vpath_handle *vp)
  29. {
  30. u64 val64;
  31. struct __vxge_hw_virtualpath *vpath;
  32. struct vxge_hw_vpath_reg __iomem *vp_reg;
  33. enum vxge_hw_status status = VXGE_HW_OK;
  34. if (vp == NULL) {
  35. status = VXGE_HW_ERR_INVALID_HANDLE;
  36. goto exit;
  37. }
  38. vpath = vp->vpath;
  39. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  40. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  41. goto exit;
  42. }
  43. vp_reg = vpath->vp_reg;
  44. writeq(VXGE_HW_INTR_MASK_ALL, &vp_reg->kdfcctl_errors_reg);
  45. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  46. &vp_reg->general_errors_reg);
  47. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  48. &vp_reg->pci_config_errors_reg);
  49. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  50. &vp_reg->mrpcim_to_vpath_alarm_reg);
  51. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  52. &vp_reg->srpcim_to_vpath_alarm_reg);
  53. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  54. &vp_reg->vpath_ppif_int_status);
  55. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  56. &vp_reg->srpcim_msg_to_vpath_reg);
  57. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  58. &vp_reg->vpath_pcipif_int_status);
  59. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  60. &vp_reg->prc_alarm_reg);
  61. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  62. &vp_reg->wrdma_alarm_status);
  63. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  64. &vp_reg->asic_ntwk_vp_err_reg);
  65. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  66. &vp_reg->xgmac_vp_int_status);
  67. val64 = readq(&vp_reg->vpath_general_int_status);
  68. /* Mask unwanted interrupts */
  69. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  70. &vp_reg->vpath_pcipif_int_mask);
  71. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  72. &vp_reg->srpcim_msg_to_vpath_mask);
  73. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  74. &vp_reg->srpcim_to_vpath_alarm_mask);
  75. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  76. &vp_reg->mrpcim_to_vpath_alarm_mask);
  77. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  78. &vp_reg->pci_config_errors_mask);
  79. /* Unmask the individual interrupts */
  80. writeq((u32)vxge_bVALn((VXGE_HW_GENERAL_ERRORS_REG_DBLGEN_FIFO1_OVRFLOW|
  81. VXGE_HW_GENERAL_ERRORS_REG_DBLGEN_FIFO2_OVRFLOW|
  82. VXGE_HW_GENERAL_ERRORS_REG_STATSB_DROP_TIMEOUT_REQ|
  83. VXGE_HW_GENERAL_ERRORS_REG_STATSB_PIF_CHAIN_ERR), 0, 32),
  84. &vp_reg->general_errors_mask);
  85. __vxge_hw_pio_mem_write32_upper(
  86. (u32)vxge_bVALn((VXGE_HW_KDFCCTL_ERRORS_REG_KDFCCTL_FIFO1_OVRWR|
  87. VXGE_HW_KDFCCTL_ERRORS_REG_KDFCCTL_FIFO2_OVRWR|
  88. VXGE_HW_KDFCCTL_ERRORS_REG_KDFCCTL_FIFO1_POISON|
  89. VXGE_HW_KDFCCTL_ERRORS_REG_KDFCCTL_FIFO2_POISON|
  90. VXGE_HW_KDFCCTL_ERRORS_REG_KDFCCTL_FIFO1_DMA_ERR|
  91. VXGE_HW_KDFCCTL_ERRORS_REG_KDFCCTL_FIFO2_DMA_ERR), 0, 32),
  92. &vp_reg->kdfcctl_errors_mask);
  93. __vxge_hw_pio_mem_write32_upper(0, &vp_reg->vpath_ppif_int_mask);
  94. __vxge_hw_pio_mem_write32_upper(
  95. (u32)vxge_bVALn(VXGE_HW_PRC_ALARM_REG_PRC_RING_BUMP, 0, 32),
  96. &vp_reg->prc_alarm_mask);
  97. __vxge_hw_pio_mem_write32_upper(0, &vp_reg->wrdma_alarm_mask);
  98. __vxge_hw_pio_mem_write32_upper(0, &vp_reg->xgmac_vp_int_mask);
  99. if (vpath->hldev->first_vp_id != vpath->vp_id)
  100. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  101. &vp_reg->asic_ntwk_vp_err_mask);
  102. else
  103. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn((
  104. VXGE_HW_ASIC_NTWK_VP_ERR_REG_XMACJ_NTWK_REAFFIRMED_FAULT |
  105. VXGE_HW_ASIC_NTWK_VP_ERR_REG_XMACJ_NTWK_REAFFIRMED_OK), 0, 32),
  106. &vp_reg->asic_ntwk_vp_err_mask);
  107. __vxge_hw_pio_mem_write32_upper(0,
  108. &vp_reg->vpath_general_int_mask);
  109. exit:
  110. return status;
  111. }
  112. /*
  113. * vxge_hw_vpath_intr_disable - Disable vpath interrupts.
  114. * @vp: Virtual Path handle.
  115. *
  116. * Disable vpath interrupts. The function is to be executed the last in
  117. * vpath initialization sequence.
  118. *
  119. * See also: vxge_hw_vpath_intr_enable()
  120. */
  121. enum vxge_hw_status vxge_hw_vpath_intr_disable(
  122. struct __vxge_hw_vpath_handle *vp)
  123. {
  124. u64 val64;
  125. struct __vxge_hw_virtualpath *vpath;
  126. enum vxge_hw_status status = VXGE_HW_OK;
  127. struct vxge_hw_vpath_reg __iomem *vp_reg;
  128. if (vp == NULL) {
  129. status = VXGE_HW_ERR_INVALID_HANDLE;
  130. goto exit;
  131. }
  132. vpath = vp->vpath;
  133. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  134. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  135. goto exit;
  136. }
  137. vp_reg = vpath->vp_reg;
  138. __vxge_hw_pio_mem_write32_upper(
  139. (u32)VXGE_HW_INTR_MASK_ALL,
  140. &vp_reg->vpath_general_int_mask);
  141. val64 = VXGE_HW_TIM_CLR_INT_EN_VP(1 << (16 - vpath->vp_id));
  142. writeq(VXGE_HW_INTR_MASK_ALL, &vp_reg->kdfcctl_errors_mask);
  143. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  144. &vp_reg->general_errors_mask);
  145. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  146. &vp_reg->pci_config_errors_mask);
  147. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  148. &vp_reg->mrpcim_to_vpath_alarm_mask);
  149. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  150. &vp_reg->srpcim_to_vpath_alarm_mask);
  151. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  152. &vp_reg->vpath_ppif_int_mask);
  153. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  154. &vp_reg->srpcim_msg_to_vpath_mask);
  155. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  156. &vp_reg->vpath_pcipif_int_mask);
  157. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  158. &vp_reg->wrdma_alarm_mask);
  159. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  160. &vp_reg->prc_alarm_mask);
  161. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  162. &vp_reg->xgmac_vp_int_mask);
  163. __vxge_hw_pio_mem_write32_upper((u32)VXGE_HW_INTR_MASK_ALL,
  164. &vp_reg->asic_ntwk_vp_err_mask);
  165. exit:
  166. return status;
  167. }
  168. void vxge_hw_vpath_tti_ci_set(struct __vxge_hw_fifo *fifo)
  169. {
  170. struct vxge_hw_vpath_reg __iomem *vp_reg;
  171. struct vxge_hw_vp_config *config;
  172. u64 val64;
  173. if (fifo->config->enable != VXGE_HW_FIFO_ENABLE)
  174. return;
  175. vp_reg = fifo->vp_reg;
  176. config = container_of(fifo->config, struct vxge_hw_vp_config, fifo);
  177. if (config->tti.timer_ci_en != VXGE_HW_TIM_TIMER_CI_ENABLE) {
  178. config->tti.timer_ci_en = VXGE_HW_TIM_TIMER_CI_ENABLE;
  179. val64 = readq(&vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_TX]);
  180. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI;
  181. fifo->tim_tti_cfg1_saved = val64;
  182. writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_TX]);
  183. }
  184. }
  185. void vxge_hw_vpath_dynamic_rti_ci_set(struct __vxge_hw_ring *ring)
  186. {
  187. u64 val64 = ring->tim_rti_cfg1_saved;
  188. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI;
  189. ring->tim_rti_cfg1_saved = val64;
  190. writeq(val64, &ring->vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_RX]);
  191. }
  192. void vxge_hw_vpath_dynamic_tti_rtimer_set(struct __vxge_hw_fifo *fifo)
  193. {
  194. u64 val64 = fifo->tim_tti_cfg3_saved;
  195. u64 timer = (fifo->rtimer * 1000) / 272;
  196. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(0x3ffffff);
  197. if (timer)
  198. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(timer) |
  199. VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_EVENT_SF(5);
  200. writeq(val64, &fifo->vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_TX]);
  201. /* tti_cfg3_saved is not updated again because it is
  202. * initialized at one place only - init time.
  203. */
  204. }
  205. void vxge_hw_vpath_dynamic_rti_rtimer_set(struct __vxge_hw_ring *ring)
  206. {
  207. u64 val64 = ring->tim_rti_cfg3_saved;
  208. u64 timer = (ring->rtimer * 1000) / 272;
  209. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(0x3ffffff);
  210. if (timer)
  211. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(timer) |
  212. VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_EVENT_SF(4);
  213. writeq(val64, &ring->vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_RX]);
  214. /* rti_cfg3_saved is not updated again because it is
  215. * initialized at one place only - init time.
  216. */
  217. }
  218. /**
  219. * vxge_hw_channel_msix_mask - Mask MSIX Vector.
  220. * @channeh: Channel for rx or tx handle
  221. * @msix_id: MSIX ID
  222. *
  223. * The function masks the msix interrupt for the given msix_id
  224. *
  225. * Returns: 0
  226. */
  227. void vxge_hw_channel_msix_mask(struct __vxge_hw_channel *channel, int msix_id)
  228. {
  229. __vxge_hw_pio_mem_write32_upper(
  230. (u32)vxge_bVALn(vxge_mBIT(msix_id >> 2), 0, 32),
  231. &channel->common_reg->set_msix_mask_vect[msix_id%4]);
  232. }
  233. /**
  234. * vxge_hw_channel_msix_unmask - Unmask the MSIX Vector.
  235. * @channeh: Channel for rx or tx handle
  236. * @msix_id: MSI ID
  237. *
  238. * The function unmasks the msix interrupt for the given msix_id
  239. *
  240. * Returns: 0
  241. */
  242. void
  243. vxge_hw_channel_msix_unmask(struct __vxge_hw_channel *channel, int msix_id)
  244. {
  245. __vxge_hw_pio_mem_write32_upper(
  246. (u32)vxge_bVALn(vxge_mBIT(msix_id >> 2), 0, 32),
  247. &channel->common_reg->clear_msix_mask_vect[msix_id%4]);
  248. }
  249. /**
  250. * vxge_hw_channel_msix_clear - Unmask the MSIX Vector.
  251. * @channel: Channel for rx or tx handle
  252. * @msix_id: MSI ID
  253. *
  254. * The function unmasks the msix interrupt for the given msix_id
  255. * if configured in MSIX oneshot mode
  256. *
  257. * Returns: 0
  258. */
  259. void vxge_hw_channel_msix_clear(struct __vxge_hw_channel *channel, int msix_id)
  260. {
  261. __vxge_hw_pio_mem_write32_upper(
  262. (u32) vxge_bVALn(vxge_mBIT(msix_id >> 2), 0, 32),
  263. &channel->common_reg->clr_msix_one_shot_vec[msix_id % 4]);
  264. }
  265. /**
  266. * vxge_hw_device_set_intr_type - Updates the configuration
  267. * with new interrupt type.
  268. * @hldev: HW device handle.
  269. * @intr_mode: New interrupt type
  270. */
  271. u32 vxge_hw_device_set_intr_type(struct __vxge_hw_device *hldev, u32 intr_mode)
  272. {
  273. if ((intr_mode != VXGE_HW_INTR_MODE_IRQLINE) &&
  274. (intr_mode != VXGE_HW_INTR_MODE_MSIX) &&
  275. (intr_mode != VXGE_HW_INTR_MODE_MSIX_ONE_SHOT) &&
  276. (intr_mode != VXGE_HW_INTR_MODE_DEF))
  277. intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
  278. hldev->config.intr_mode = intr_mode;
  279. return intr_mode;
  280. }
  281. /**
  282. * vxge_hw_device_intr_enable - Enable interrupts.
  283. * @hldev: HW device handle.
  284. * @op: One of the enum vxge_hw_device_intr enumerated values specifying
  285. * the type(s) of interrupts to enable.
  286. *
  287. * Enable Titan interrupts. The function is to be executed the last in
  288. * Titan initialization sequence.
  289. *
  290. * See also: vxge_hw_device_intr_disable()
  291. */
  292. void vxge_hw_device_intr_enable(struct __vxge_hw_device *hldev)
  293. {
  294. u32 i;
  295. u64 val64;
  296. u32 val32;
  297. vxge_hw_device_mask_all(hldev);
  298. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  299. if (!(hldev->vpaths_deployed & vxge_mBIT(i)))
  300. continue;
  301. vxge_hw_vpath_intr_enable(
  302. VXGE_HW_VIRTUAL_PATH_HANDLE(&hldev->virtual_paths[i]));
  303. }
  304. if (hldev->config.intr_mode == VXGE_HW_INTR_MODE_IRQLINE) {
  305. val64 = hldev->tim_int_mask0[VXGE_HW_VPATH_INTR_TX] |
  306. hldev->tim_int_mask0[VXGE_HW_VPATH_INTR_RX];
  307. if (val64 != 0) {
  308. writeq(val64, &hldev->common_reg->tim_int_status0);
  309. writeq(~val64, &hldev->common_reg->tim_int_mask0);
  310. }
  311. val32 = hldev->tim_int_mask1[VXGE_HW_VPATH_INTR_TX] |
  312. hldev->tim_int_mask1[VXGE_HW_VPATH_INTR_RX];
  313. if (val32 != 0) {
  314. __vxge_hw_pio_mem_write32_upper(val32,
  315. &hldev->common_reg->tim_int_status1);
  316. __vxge_hw_pio_mem_write32_upper(~val32,
  317. &hldev->common_reg->tim_int_mask1);
  318. }
  319. }
  320. val64 = readq(&hldev->common_reg->titan_general_int_status);
  321. vxge_hw_device_unmask_all(hldev);
  322. }
  323. /**
  324. * vxge_hw_device_intr_disable - Disable Titan interrupts.
  325. * @hldev: HW device handle.
  326. * @op: One of the enum vxge_hw_device_intr enumerated values specifying
  327. * the type(s) of interrupts to disable.
  328. *
  329. * Disable Titan interrupts.
  330. *
  331. * See also: vxge_hw_device_intr_enable()
  332. */
  333. void vxge_hw_device_intr_disable(struct __vxge_hw_device *hldev)
  334. {
  335. u32 i;
  336. vxge_hw_device_mask_all(hldev);
  337. /* mask all the tim interrupts */
  338. writeq(VXGE_HW_INTR_MASK_ALL, &hldev->common_reg->tim_int_mask0);
  339. __vxge_hw_pio_mem_write32_upper(VXGE_HW_DEFAULT_32,
  340. &hldev->common_reg->tim_int_mask1);
  341. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  342. if (!(hldev->vpaths_deployed & vxge_mBIT(i)))
  343. continue;
  344. vxge_hw_vpath_intr_disable(
  345. VXGE_HW_VIRTUAL_PATH_HANDLE(&hldev->virtual_paths[i]));
  346. }
  347. }
  348. /**
  349. * vxge_hw_device_mask_all - Mask all device interrupts.
  350. * @hldev: HW device handle.
  351. *
  352. * Mask all device interrupts.
  353. *
  354. * See also: vxge_hw_device_unmask_all()
  355. */
  356. void vxge_hw_device_mask_all(struct __vxge_hw_device *hldev)
  357. {
  358. u64 val64;
  359. val64 = VXGE_HW_TITAN_MASK_ALL_INT_ALARM |
  360. VXGE_HW_TITAN_MASK_ALL_INT_TRAFFIC;
  361. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32),
  362. &hldev->common_reg->titan_mask_all_int);
  363. }
  364. /**
  365. * vxge_hw_device_unmask_all - Unmask all device interrupts.
  366. * @hldev: HW device handle.
  367. *
  368. * Unmask all device interrupts.
  369. *
  370. * See also: vxge_hw_device_mask_all()
  371. */
  372. void vxge_hw_device_unmask_all(struct __vxge_hw_device *hldev)
  373. {
  374. u64 val64 = 0;
  375. if (hldev->config.intr_mode == VXGE_HW_INTR_MODE_IRQLINE)
  376. val64 = VXGE_HW_TITAN_MASK_ALL_INT_TRAFFIC;
  377. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32),
  378. &hldev->common_reg->titan_mask_all_int);
  379. }
  380. /**
  381. * vxge_hw_device_flush_io - Flush io writes.
  382. * @hldev: HW device handle.
  383. *
  384. * The function performs a read operation to flush io writes.
  385. *
  386. * Returns: void
  387. */
  388. void vxge_hw_device_flush_io(struct __vxge_hw_device *hldev)
  389. {
  390. u32 val32;
  391. val32 = readl(&hldev->common_reg->titan_general_int_status);
  392. }
  393. /**
  394. * __vxge_hw_device_handle_error - Handle error
  395. * @hldev: HW device
  396. * @vp_id: Vpath Id
  397. * @type: Error type. Please see enum vxge_hw_event{}
  398. *
  399. * Handle error.
  400. */
  401. static enum vxge_hw_status
  402. __vxge_hw_device_handle_error(struct __vxge_hw_device *hldev, u32 vp_id,
  403. enum vxge_hw_event type)
  404. {
  405. switch (type) {
  406. case VXGE_HW_EVENT_UNKNOWN:
  407. break;
  408. case VXGE_HW_EVENT_RESET_START:
  409. case VXGE_HW_EVENT_RESET_COMPLETE:
  410. case VXGE_HW_EVENT_LINK_DOWN:
  411. case VXGE_HW_EVENT_LINK_UP:
  412. goto out;
  413. case VXGE_HW_EVENT_ALARM_CLEARED:
  414. goto out;
  415. case VXGE_HW_EVENT_ECCERR:
  416. case VXGE_HW_EVENT_MRPCIM_ECCERR:
  417. goto out;
  418. case VXGE_HW_EVENT_FIFO_ERR:
  419. case VXGE_HW_EVENT_VPATH_ERR:
  420. case VXGE_HW_EVENT_CRITICAL_ERR:
  421. case VXGE_HW_EVENT_SERR:
  422. break;
  423. case VXGE_HW_EVENT_SRPCIM_SERR:
  424. case VXGE_HW_EVENT_MRPCIM_SERR:
  425. goto out;
  426. case VXGE_HW_EVENT_SLOT_FREEZE:
  427. break;
  428. default:
  429. vxge_assert(0);
  430. goto out;
  431. }
  432. /* notify driver */
  433. if (hldev->uld_callbacks->crit_err)
  434. hldev->uld_callbacks->crit_err(hldev,
  435. type, vp_id);
  436. out:
  437. return VXGE_HW_OK;
  438. }
  439. /*
  440. * __vxge_hw_device_handle_link_down_ind
  441. * @hldev: HW device handle.
  442. *
  443. * Link down indication handler. The function is invoked by HW when
  444. * Titan indicates that the link is down.
  445. */
  446. static enum vxge_hw_status
  447. __vxge_hw_device_handle_link_down_ind(struct __vxge_hw_device *hldev)
  448. {
  449. /*
  450. * If the previous link state is not down, return.
  451. */
  452. if (hldev->link_state == VXGE_HW_LINK_DOWN)
  453. goto exit;
  454. hldev->link_state = VXGE_HW_LINK_DOWN;
  455. /* notify driver */
  456. if (hldev->uld_callbacks->link_down)
  457. hldev->uld_callbacks->link_down(hldev);
  458. exit:
  459. return VXGE_HW_OK;
  460. }
  461. /*
  462. * __vxge_hw_device_handle_link_up_ind
  463. * @hldev: HW device handle.
  464. *
  465. * Link up indication handler. The function is invoked by HW when
  466. * Titan indicates that the link is up for programmable amount of time.
  467. */
  468. static enum vxge_hw_status
  469. __vxge_hw_device_handle_link_up_ind(struct __vxge_hw_device *hldev)
  470. {
  471. /*
  472. * If the previous link state is not down, return.
  473. */
  474. if (hldev->link_state == VXGE_HW_LINK_UP)
  475. goto exit;
  476. hldev->link_state = VXGE_HW_LINK_UP;
  477. /* notify driver */
  478. if (hldev->uld_callbacks->link_up)
  479. hldev->uld_callbacks->link_up(hldev);
  480. exit:
  481. return VXGE_HW_OK;
  482. }
  483. /*
  484. * __vxge_hw_vpath_alarm_process - Process Alarms.
  485. * @vpath: Virtual Path.
  486. * @skip_alarms: Do not clear the alarms
  487. *
  488. * Process vpath alarms.
  489. *
  490. */
  491. static enum vxge_hw_status
  492. __vxge_hw_vpath_alarm_process(struct __vxge_hw_virtualpath *vpath,
  493. u32 skip_alarms)
  494. {
  495. u64 val64;
  496. u64 alarm_status;
  497. u64 pic_status;
  498. struct __vxge_hw_device *hldev = NULL;
  499. enum vxge_hw_event alarm_event = VXGE_HW_EVENT_UNKNOWN;
  500. u64 mask64;
  501. struct vxge_hw_vpath_stats_sw_info *sw_stats;
  502. struct vxge_hw_vpath_reg __iomem *vp_reg;
  503. if (vpath == NULL) {
  504. alarm_event = VXGE_HW_SET_LEVEL(VXGE_HW_EVENT_UNKNOWN,
  505. alarm_event);
  506. goto out2;
  507. }
  508. hldev = vpath->hldev;
  509. vp_reg = vpath->vp_reg;
  510. alarm_status = readq(&vp_reg->vpath_general_int_status);
  511. if (alarm_status == VXGE_HW_ALL_FOXES) {
  512. alarm_event = VXGE_HW_SET_LEVEL(VXGE_HW_EVENT_SLOT_FREEZE,
  513. alarm_event);
  514. goto out;
  515. }
  516. sw_stats = vpath->sw_stats;
  517. if (alarm_status & ~(
  518. VXGE_HW_VPATH_GENERAL_INT_STATUS_PIC_INT |
  519. VXGE_HW_VPATH_GENERAL_INT_STATUS_PCI_INT |
  520. VXGE_HW_VPATH_GENERAL_INT_STATUS_WRDMA_INT |
  521. VXGE_HW_VPATH_GENERAL_INT_STATUS_XMAC_INT)) {
  522. sw_stats->error_stats.unknown_alarms++;
  523. alarm_event = VXGE_HW_SET_LEVEL(VXGE_HW_EVENT_UNKNOWN,
  524. alarm_event);
  525. goto out;
  526. }
  527. if (alarm_status & VXGE_HW_VPATH_GENERAL_INT_STATUS_XMAC_INT) {
  528. val64 = readq(&vp_reg->xgmac_vp_int_status);
  529. if (val64 &
  530. VXGE_HW_XGMAC_VP_INT_STATUS_ASIC_NTWK_VP_ERR_ASIC_NTWK_VP_INT) {
  531. val64 = readq(&vp_reg->asic_ntwk_vp_err_reg);
  532. if (((val64 &
  533. VXGE_HW_ASIC_NW_VP_ERR_REG_XMACJ_STN_FLT) &&
  534. (!(val64 &
  535. VXGE_HW_ASIC_NW_VP_ERR_REG_XMACJ_STN_OK))) ||
  536. ((val64 &
  537. VXGE_HW_ASIC_NW_VP_ERR_REG_XMACJ_STN_FLT_OCCURR) &&
  538. (!(val64 &
  539. VXGE_HW_ASIC_NW_VP_ERR_REG_XMACJ_STN_OK_OCCURR)
  540. ))) {
  541. sw_stats->error_stats.network_sustained_fault++;
  542. writeq(
  543. VXGE_HW_ASIC_NW_VP_ERR_REG_XMACJ_STN_FLT,
  544. &vp_reg->asic_ntwk_vp_err_mask);
  545. __vxge_hw_device_handle_link_down_ind(hldev);
  546. alarm_event = VXGE_HW_SET_LEVEL(
  547. VXGE_HW_EVENT_LINK_DOWN, alarm_event);
  548. }
  549. if (((val64 &
  550. VXGE_HW_ASIC_NW_VP_ERR_REG_XMACJ_STN_OK) &&
  551. (!(val64 &
  552. VXGE_HW_ASIC_NW_VP_ERR_REG_XMACJ_STN_FLT))) ||
  553. ((val64 &
  554. VXGE_HW_ASIC_NW_VP_ERR_REG_XMACJ_STN_OK_OCCURR) &&
  555. (!(val64 &
  556. VXGE_HW_ASIC_NW_VP_ERR_REG_XMACJ_STN_FLT_OCCURR)
  557. ))) {
  558. sw_stats->error_stats.network_sustained_ok++;
  559. writeq(
  560. VXGE_HW_ASIC_NW_VP_ERR_REG_XMACJ_STN_OK,
  561. &vp_reg->asic_ntwk_vp_err_mask);
  562. __vxge_hw_device_handle_link_up_ind(hldev);
  563. alarm_event = VXGE_HW_SET_LEVEL(
  564. VXGE_HW_EVENT_LINK_UP, alarm_event);
  565. }
  566. writeq(VXGE_HW_INTR_MASK_ALL,
  567. &vp_reg->asic_ntwk_vp_err_reg);
  568. alarm_event = VXGE_HW_SET_LEVEL(
  569. VXGE_HW_EVENT_ALARM_CLEARED, alarm_event);
  570. if (skip_alarms)
  571. return VXGE_HW_OK;
  572. }
  573. }
  574. if (alarm_status & VXGE_HW_VPATH_GENERAL_INT_STATUS_PIC_INT) {
  575. pic_status = readq(&vp_reg->vpath_ppif_int_status);
  576. if (pic_status &
  577. VXGE_HW_VPATH_PPIF_INT_STATUS_GENERAL_ERRORS_GENERAL_INT) {
  578. val64 = readq(&vp_reg->general_errors_reg);
  579. mask64 = readq(&vp_reg->general_errors_mask);
  580. if ((val64 &
  581. VXGE_HW_GENERAL_ERRORS_REG_INI_SERR_DET) &
  582. ~mask64) {
  583. sw_stats->error_stats.ini_serr_det++;
  584. alarm_event = VXGE_HW_SET_LEVEL(
  585. VXGE_HW_EVENT_SERR, alarm_event);
  586. }
  587. if ((val64 &
  588. VXGE_HW_GENERAL_ERRORS_REG_DBLGEN_FIFO0_OVRFLOW) &
  589. ~mask64) {
  590. sw_stats->error_stats.dblgen_fifo0_overflow++;
  591. alarm_event = VXGE_HW_SET_LEVEL(
  592. VXGE_HW_EVENT_FIFO_ERR, alarm_event);
  593. }
  594. if ((val64 &
  595. VXGE_HW_GENERAL_ERRORS_REG_STATSB_PIF_CHAIN_ERR) &
  596. ~mask64)
  597. sw_stats->error_stats.statsb_pif_chain_error++;
  598. if ((val64 &
  599. VXGE_HW_GENERAL_ERRORS_REG_STATSB_DROP_TIMEOUT_REQ) &
  600. ~mask64)
  601. sw_stats->error_stats.statsb_drop_timeout++;
  602. if ((val64 &
  603. VXGE_HW_GENERAL_ERRORS_REG_TGT_ILLEGAL_ACCESS) &
  604. ~mask64)
  605. sw_stats->error_stats.target_illegal_access++;
  606. if (!skip_alarms) {
  607. writeq(VXGE_HW_INTR_MASK_ALL,
  608. &vp_reg->general_errors_reg);
  609. alarm_event = VXGE_HW_SET_LEVEL(
  610. VXGE_HW_EVENT_ALARM_CLEARED,
  611. alarm_event);
  612. }
  613. }
  614. if (pic_status &
  615. VXGE_HW_VPATH_PPIF_INT_STATUS_KDFCCTL_ERRORS_KDFCCTL_INT) {
  616. val64 = readq(&vp_reg->kdfcctl_errors_reg);
  617. mask64 = readq(&vp_reg->kdfcctl_errors_mask);
  618. if ((val64 &
  619. VXGE_HW_KDFCCTL_ERRORS_REG_KDFCCTL_FIFO0_OVRWR) &
  620. ~mask64) {
  621. sw_stats->error_stats.kdfcctl_fifo0_overwrite++;
  622. alarm_event = VXGE_HW_SET_LEVEL(
  623. VXGE_HW_EVENT_FIFO_ERR,
  624. alarm_event);
  625. }
  626. if ((val64 &
  627. VXGE_HW_KDFCCTL_ERRORS_REG_KDFCCTL_FIFO0_POISON) &
  628. ~mask64) {
  629. sw_stats->error_stats.kdfcctl_fifo0_poison++;
  630. alarm_event = VXGE_HW_SET_LEVEL(
  631. VXGE_HW_EVENT_FIFO_ERR,
  632. alarm_event);
  633. }
  634. if ((val64 &
  635. VXGE_HW_KDFCCTL_ERRORS_REG_KDFCCTL_FIFO0_DMA_ERR) &
  636. ~mask64) {
  637. sw_stats->error_stats.kdfcctl_fifo0_dma_error++;
  638. alarm_event = VXGE_HW_SET_LEVEL(
  639. VXGE_HW_EVENT_FIFO_ERR,
  640. alarm_event);
  641. }
  642. if (!skip_alarms) {
  643. writeq(VXGE_HW_INTR_MASK_ALL,
  644. &vp_reg->kdfcctl_errors_reg);
  645. alarm_event = VXGE_HW_SET_LEVEL(
  646. VXGE_HW_EVENT_ALARM_CLEARED,
  647. alarm_event);
  648. }
  649. }
  650. }
  651. if (alarm_status & VXGE_HW_VPATH_GENERAL_INT_STATUS_WRDMA_INT) {
  652. val64 = readq(&vp_reg->wrdma_alarm_status);
  653. if (val64 & VXGE_HW_WRDMA_ALARM_STATUS_PRC_ALARM_PRC_INT) {
  654. val64 = readq(&vp_reg->prc_alarm_reg);
  655. mask64 = readq(&vp_reg->prc_alarm_mask);
  656. if ((val64 & VXGE_HW_PRC_ALARM_REG_PRC_RING_BUMP)&
  657. ~mask64)
  658. sw_stats->error_stats.prc_ring_bumps++;
  659. if ((val64 & VXGE_HW_PRC_ALARM_REG_PRC_RXDCM_SC_ERR) &
  660. ~mask64) {
  661. sw_stats->error_stats.prc_rxdcm_sc_err++;
  662. alarm_event = VXGE_HW_SET_LEVEL(
  663. VXGE_HW_EVENT_VPATH_ERR,
  664. alarm_event);
  665. }
  666. if ((val64 & VXGE_HW_PRC_ALARM_REG_PRC_RXDCM_SC_ABORT)
  667. & ~mask64) {
  668. sw_stats->error_stats.prc_rxdcm_sc_abort++;
  669. alarm_event = VXGE_HW_SET_LEVEL(
  670. VXGE_HW_EVENT_VPATH_ERR,
  671. alarm_event);
  672. }
  673. if ((val64 & VXGE_HW_PRC_ALARM_REG_PRC_QUANTA_SIZE_ERR)
  674. & ~mask64) {
  675. sw_stats->error_stats.prc_quanta_size_err++;
  676. alarm_event = VXGE_HW_SET_LEVEL(
  677. VXGE_HW_EVENT_VPATH_ERR,
  678. alarm_event);
  679. }
  680. if (!skip_alarms) {
  681. writeq(VXGE_HW_INTR_MASK_ALL,
  682. &vp_reg->prc_alarm_reg);
  683. alarm_event = VXGE_HW_SET_LEVEL(
  684. VXGE_HW_EVENT_ALARM_CLEARED,
  685. alarm_event);
  686. }
  687. }
  688. }
  689. out:
  690. hldev->stats.sw_dev_err_stats.vpath_alarms++;
  691. out2:
  692. if ((alarm_event == VXGE_HW_EVENT_ALARM_CLEARED) ||
  693. (alarm_event == VXGE_HW_EVENT_UNKNOWN))
  694. return VXGE_HW_OK;
  695. __vxge_hw_device_handle_error(hldev, vpath->vp_id, alarm_event);
  696. if (alarm_event == VXGE_HW_EVENT_SERR)
  697. return VXGE_HW_ERR_CRITICAL;
  698. return (alarm_event == VXGE_HW_EVENT_SLOT_FREEZE) ?
  699. VXGE_HW_ERR_SLOT_FREEZE :
  700. (alarm_event == VXGE_HW_EVENT_FIFO_ERR) ? VXGE_HW_ERR_FIFO :
  701. VXGE_HW_ERR_VPATH;
  702. }
  703. /**
  704. * vxge_hw_device_begin_irq - Begin IRQ processing.
  705. * @hldev: HW device handle.
  706. * @skip_alarms: Do not clear the alarms
  707. * @reason: "Reason" for the interrupt, the value of Titan's
  708. * general_int_status register.
  709. *
  710. * The function performs two actions, It first checks whether (shared IRQ) the
  711. * interrupt was raised by the device. Next, it masks the device interrupts.
  712. *
  713. * Note:
  714. * vxge_hw_device_begin_irq() does not flush MMIO writes through the
  715. * bridge. Therefore, two back-to-back interrupts are potentially possible.
  716. *
  717. * Returns: 0, if the interrupt is not "ours" (note that in this case the
  718. * device remain enabled).
  719. * Otherwise, vxge_hw_device_begin_irq() returns 64bit general adapter
  720. * status.
  721. */
  722. enum vxge_hw_status vxge_hw_device_begin_irq(struct __vxge_hw_device *hldev,
  723. u32 skip_alarms, u64 *reason)
  724. {
  725. u32 i;
  726. u64 val64;
  727. u64 adapter_status;
  728. u64 vpath_mask;
  729. enum vxge_hw_status ret = VXGE_HW_OK;
  730. val64 = readq(&hldev->common_reg->titan_general_int_status);
  731. if (unlikely(!val64)) {
  732. /* not Titan interrupt */
  733. *reason = 0;
  734. ret = VXGE_HW_ERR_WRONG_IRQ;
  735. goto exit;
  736. }
  737. if (unlikely(val64 == VXGE_HW_ALL_FOXES)) {
  738. adapter_status = readq(&hldev->common_reg->adapter_status);
  739. if (adapter_status == VXGE_HW_ALL_FOXES) {
  740. __vxge_hw_device_handle_error(hldev,
  741. NULL_VPID, VXGE_HW_EVENT_SLOT_FREEZE);
  742. *reason = 0;
  743. ret = VXGE_HW_ERR_SLOT_FREEZE;
  744. goto exit;
  745. }
  746. }
  747. hldev->stats.sw_dev_info_stats.total_intr_cnt++;
  748. *reason = val64;
  749. vpath_mask = hldev->vpaths_deployed >>
  750. (64 - VXGE_HW_MAX_VIRTUAL_PATHS);
  751. if (val64 &
  752. VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(vpath_mask)) {
  753. hldev->stats.sw_dev_info_stats.traffic_intr_cnt++;
  754. return VXGE_HW_OK;
  755. }
  756. hldev->stats.sw_dev_info_stats.not_traffic_intr_cnt++;
  757. if (unlikely(val64 &
  758. VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_ALARM_INT)) {
  759. enum vxge_hw_status error_level = VXGE_HW_OK;
  760. hldev->stats.sw_dev_err_stats.vpath_alarms++;
  761. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  762. if (!(hldev->vpaths_deployed & vxge_mBIT(i)))
  763. continue;
  764. ret = __vxge_hw_vpath_alarm_process(
  765. &hldev->virtual_paths[i], skip_alarms);
  766. error_level = VXGE_HW_SET_LEVEL(ret, error_level);
  767. if (unlikely((ret == VXGE_HW_ERR_CRITICAL) ||
  768. (ret == VXGE_HW_ERR_SLOT_FREEZE)))
  769. break;
  770. }
  771. ret = error_level;
  772. }
  773. exit:
  774. return ret;
  775. }
  776. /**
  777. * vxge_hw_device_clear_tx_rx - Acknowledge (that is, clear) the
  778. * condition that has caused the Tx and RX interrupt.
  779. * @hldev: HW device.
  780. *
  781. * Acknowledge (that is, clear) the condition that has caused
  782. * the Tx and Rx interrupt.
  783. * See also: vxge_hw_device_begin_irq(),
  784. * vxge_hw_device_mask_tx_rx(), vxge_hw_device_unmask_tx_rx().
  785. */
  786. void vxge_hw_device_clear_tx_rx(struct __vxge_hw_device *hldev)
  787. {
  788. if ((hldev->tim_int_mask0[VXGE_HW_VPATH_INTR_TX] != 0) ||
  789. (hldev->tim_int_mask0[VXGE_HW_VPATH_INTR_RX] != 0)) {
  790. writeq((hldev->tim_int_mask0[VXGE_HW_VPATH_INTR_TX] |
  791. hldev->tim_int_mask0[VXGE_HW_VPATH_INTR_RX]),
  792. &hldev->common_reg->tim_int_status0);
  793. }
  794. if ((hldev->tim_int_mask1[VXGE_HW_VPATH_INTR_TX] != 0) ||
  795. (hldev->tim_int_mask1[VXGE_HW_VPATH_INTR_RX] != 0)) {
  796. __vxge_hw_pio_mem_write32_upper(
  797. (hldev->tim_int_mask1[VXGE_HW_VPATH_INTR_TX] |
  798. hldev->tim_int_mask1[VXGE_HW_VPATH_INTR_RX]),
  799. &hldev->common_reg->tim_int_status1);
  800. }
  801. }
  802. /*
  803. * vxge_hw_channel_dtr_alloc - Allocate a dtr from the channel
  804. * @channel: Channel
  805. * @dtrh: Buffer to return the DTR pointer
  806. *
  807. * Allocates a dtr from the reserve array. If the reserve array is empty,
  808. * it swaps the reserve and free arrays.
  809. *
  810. */
  811. static enum vxge_hw_status
  812. vxge_hw_channel_dtr_alloc(struct __vxge_hw_channel *channel, void **dtrh)
  813. {
  814. if (channel->reserve_ptr - channel->reserve_top > 0) {
  815. _alloc_after_swap:
  816. *dtrh = channel->reserve_arr[--channel->reserve_ptr];
  817. return VXGE_HW_OK;
  818. }
  819. /* switch between empty and full arrays */
  820. /* the idea behind such a design is that by having free and reserved
  821. * arrays separated we basically separated irq and non-irq parts.
  822. * i.e. no additional lock need to be done when we free a resource */
  823. if (channel->length - channel->free_ptr > 0) {
  824. swap(channel->reserve_arr, channel->free_arr);
  825. channel->reserve_ptr = channel->length;
  826. channel->reserve_top = channel->free_ptr;
  827. channel->free_ptr = channel->length;
  828. channel->stats->reserve_free_swaps_cnt++;
  829. goto _alloc_after_swap;
  830. }
  831. channel->stats->full_cnt++;
  832. *dtrh = NULL;
  833. return VXGE_HW_INF_OUT_OF_DESCRIPTORS;
  834. }
  835. /*
  836. * vxge_hw_channel_dtr_post - Post a dtr to the channel
  837. * @channelh: Channel
  838. * @dtrh: DTR pointer
  839. *
  840. * Posts a dtr to work array.
  841. *
  842. */
  843. static void
  844. vxge_hw_channel_dtr_post(struct __vxge_hw_channel *channel, void *dtrh)
  845. {
  846. vxge_assert(channel->work_arr[channel->post_index] == NULL);
  847. channel->work_arr[channel->post_index++] = dtrh;
  848. /* wrap-around */
  849. if (channel->post_index == channel->length)
  850. channel->post_index = 0;
  851. }
  852. /*
  853. * vxge_hw_channel_dtr_try_complete - Returns next completed dtr
  854. * @channel: Channel
  855. * @dtr: Buffer to return the next completed DTR pointer
  856. *
  857. * Returns the next completed dtr with out removing it from work array
  858. *
  859. */
  860. void
  861. vxge_hw_channel_dtr_try_complete(struct __vxge_hw_channel *channel, void **dtrh)
  862. {
  863. vxge_assert(channel->compl_index < channel->length);
  864. *dtrh = channel->work_arr[channel->compl_index];
  865. prefetch(*dtrh);
  866. }
  867. /*
  868. * vxge_hw_channel_dtr_complete - Removes next completed dtr from the work array
  869. * @channel: Channel handle
  870. *
  871. * Removes the next completed dtr from work array
  872. *
  873. */
  874. void vxge_hw_channel_dtr_complete(struct __vxge_hw_channel *channel)
  875. {
  876. channel->work_arr[channel->compl_index] = NULL;
  877. /* wrap-around */
  878. if (++channel->compl_index == channel->length)
  879. channel->compl_index = 0;
  880. channel->stats->total_compl_cnt++;
  881. }
  882. /*
  883. * vxge_hw_channel_dtr_free - Frees a dtr
  884. * @channel: Channel handle
  885. * @dtr: DTR pointer
  886. *
  887. * Returns the dtr to free array
  888. *
  889. */
  890. void vxge_hw_channel_dtr_free(struct __vxge_hw_channel *channel, void *dtrh)
  891. {
  892. channel->free_arr[--channel->free_ptr] = dtrh;
  893. }
  894. /*
  895. * vxge_hw_channel_dtr_count
  896. * @channel: Channel handle. Obtained via vxge_hw_channel_open().
  897. *
  898. * Retrieve number of DTRs available. This function can not be called
  899. * from data path. ring_initial_replenishi() is the only user.
  900. */
  901. int vxge_hw_channel_dtr_count(struct __vxge_hw_channel *channel)
  902. {
  903. return (channel->reserve_ptr - channel->reserve_top) +
  904. (channel->length - channel->free_ptr);
  905. }
  906. /**
  907. * vxge_hw_ring_rxd_reserve - Reserve ring descriptor.
  908. * @ring: Handle to the ring object used for receive
  909. * @rxdh: Reserved descriptor. On success HW fills this "out" parameter
  910. * with a valid handle.
  911. *
  912. * Reserve Rx descriptor for the subsequent filling-in driver
  913. * and posting on the corresponding channel (@channelh)
  914. * via vxge_hw_ring_rxd_post().
  915. *
  916. * Returns: VXGE_HW_OK - success.
  917. * VXGE_HW_INF_OUT_OF_DESCRIPTORS - Currently no descriptors available.
  918. *
  919. */
  920. enum vxge_hw_status vxge_hw_ring_rxd_reserve(struct __vxge_hw_ring *ring,
  921. void **rxdh)
  922. {
  923. enum vxge_hw_status status;
  924. struct __vxge_hw_channel *channel;
  925. channel = &ring->channel;
  926. status = vxge_hw_channel_dtr_alloc(channel, rxdh);
  927. if (status == VXGE_HW_OK) {
  928. struct vxge_hw_ring_rxd_1 *rxdp =
  929. (struct vxge_hw_ring_rxd_1 *)*rxdh;
  930. rxdp->control_0 = rxdp->control_1 = 0;
  931. }
  932. return status;
  933. }
  934. /**
  935. * vxge_hw_ring_rxd_free - Free descriptor.
  936. * @ring: Handle to the ring object used for receive
  937. * @rxdh: Descriptor handle.
  938. *
  939. * Free the reserved descriptor. This operation is "symmetrical" to
  940. * vxge_hw_ring_rxd_reserve. The "free-ing" completes the descriptor's
  941. * lifecycle.
  942. *
  943. * After free-ing (see vxge_hw_ring_rxd_free()) the descriptor again can
  944. * be:
  945. *
  946. * - reserved (vxge_hw_ring_rxd_reserve);
  947. *
  948. * - posted (vxge_hw_ring_rxd_post);
  949. *
  950. * - completed (vxge_hw_ring_rxd_next_completed);
  951. *
  952. * - and recycled again (vxge_hw_ring_rxd_free).
  953. *
  954. * For alternative state transitions and more details please refer to
  955. * the design doc.
  956. *
  957. */
  958. void vxge_hw_ring_rxd_free(struct __vxge_hw_ring *ring, void *rxdh)
  959. {
  960. struct __vxge_hw_channel *channel;
  961. channel = &ring->channel;
  962. vxge_hw_channel_dtr_free(channel, rxdh);
  963. }
  964. /**
  965. * vxge_hw_ring_rxd_pre_post - Prepare rxd and post
  966. * @ring: Handle to the ring object used for receive
  967. * @rxdh: Descriptor handle.
  968. *
  969. * This routine prepares a rxd and posts
  970. */
  971. void vxge_hw_ring_rxd_pre_post(struct __vxge_hw_ring *ring, void *rxdh)
  972. {
  973. struct __vxge_hw_channel *channel;
  974. channel = &ring->channel;
  975. vxge_hw_channel_dtr_post(channel, rxdh);
  976. }
  977. /**
  978. * vxge_hw_ring_rxd_post_post - Process rxd after post.
  979. * @ring: Handle to the ring object used for receive
  980. * @rxdh: Descriptor handle.
  981. *
  982. * Processes rxd after post
  983. */
  984. void vxge_hw_ring_rxd_post_post(struct __vxge_hw_ring *ring, void *rxdh)
  985. {
  986. struct vxge_hw_ring_rxd_1 *rxdp = (struct vxge_hw_ring_rxd_1 *)rxdh;
  987. struct __vxge_hw_channel *channel;
  988. channel = &ring->channel;
  989. rxdp->control_0 = VXGE_HW_RING_RXD_LIST_OWN_ADAPTER;
  990. if (ring->stats->common_stats.usage_cnt > 0)
  991. ring->stats->common_stats.usage_cnt--;
  992. }
  993. /**
  994. * vxge_hw_ring_rxd_post - Post descriptor on the ring.
  995. * @ring: Handle to the ring object used for receive
  996. * @rxdh: Descriptor obtained via vxge_hw_ring_rxd_reserve().
  997. *
  998. * Post descriptor on the ring.
  999. * Prior to posting the descriptor should be filled in accordance with
  1000. * Host/Titan interface specification for a given service (LL, etc.).
  1001. *
  1002. */
  1003. void vxge_hw_ring_rxd_post(struct __vxge_hw_ring *ring, void *rxdh)
  1004. {
  1005. struct vxge_hw_ring_rxd_1 *rxdp = (struct vxge_hw_ring_rxd_1 *)rxdh;
  1006. struct __vxge_hw_channel *channel;
  1007. channel = &ring->channel;
  1008. wmb();
  1009. rxdp->control_0 = VXGE_HW_RING_RXD_LIST_OWN_ADAPTER;
  1010. vxge_hw_channel_dtr_post(channel, rxdh);
  1011. if (ring->stats->common_stats.usage_cnt > 0)
  1012. ring->stats->common_stats.usage_cnt--;
  1013. }
  1014. /**
  1015. * vxge_hw_ring_rxd_post_post_wmb - Process rxd after post with memory barrier.
  1016. * @ring: Handle to the ring object used for receive
  1017. * @rxdh: Descriptor handle.
  1018. *
  1019. * Processes rxd after post with memory barrier.
  1020. */
  1021. void vxge_hw_ring_rxd_post_post_wmb(struct __vxge_hw_ring *ring, void *rxdh)
  1022. {
  1023. wmb();
  1024. vxge_hw_ring_rxd_post_post(ring, rxdh);
  1025. }
  1026. /**
  1027. * vxge_hw_ring_rxd_next_completed - Get the _next_ completed descriptor.
  1028. * @ring: Handle to the ring object used for receive
  1029. * @rxdh: Descriptor handle. Returned by HW.
  1030. * @t_code: Transfer code, as per Titan User Guide,
  1031. * Receive Descriptor Format. Returned by HW.
  1032. *
  1033. * Retrieve the _next_ completed descriptor.
  1034. * HW uses ring callback (*vxge_hw_ring_callback_f) to notifiy
  1035. * driver of new completed descriptors. After that
  1036. * the driver can use vxge_hw_ring_rxd_next_completed to retrieve the rest
  1037. * completions (the very first completion is passed by HW via
  1038. * vxge_hw_ring_callback_f).
  1039. *
  1040. * Implementation-wise, the driver is free to call
  1041. * vxge_hw_ring_rxd_next_completed either immediately from inside the
  1042. * ring callback, or in a deferred fashion and separate (from HW)
  1043. * context.
  1044. *
  1045. * Non-zero @t_code means failure to fill-in receive buffer(s)
  1046. * of the descriptor.
  1047. * For instance, parity error detected during the data transfer.
  1048. * In this case Titan will complete the descriptor and indicate
  1049. * for the host that the received data is not to be used.
  1050. * For details please refer to Titan User Guide.
  1051. *
  1052. * Returns: VXGE_HW_OK - success.
  1053. * VXGE_HW_INF_NO_MORE_COMPLETED_DESCRIPTORS - No completed descriptors
  1054. * are currently available for processing.
  1055. *
  1056. * See also: vxge_hw_ring_callback_f{},
  1057. * vxge_hw_fifo_rxd_next_completed(), enum vxge_hw_status{}.
  1058. */
  1059. enum vxge_hw_status vxge_hw_ring_rxd_next_completed(
  1060. struct __vxge_hw_ring *ring, void **rxdh, u8 *t_code)
  1061. {
  1062. struct __vxge_hw_channel *channel;
  1063. struct vxge_hw_ring_rxd_1 *rxdp;
  1064. enum vxge_hw_status status = VXGE_HW_OK;
  1065. u64 control_0, own;
  1066. channel = &ring->channel;
  1067. vxge_hw_channel_dtr_try_complete(channel, rxdh);
  1068. rxdp = *rxdh;
  1069. if (rxdp == NULL) {
  1070. status = VXGE_HW_INF_NO_MORE_COMPLETED_DESCRIPTORS;
  1071. goto exit;
  1072. }
  1073. control_0 = rxdp->control_0;
  1074. own = control_0 & VXGE_HW_RING_RXD_LIST_OWN_ADAPTER;
  1075. *t_code = (u8)VXGE_HW_RING_RXD_T_CODE_GET(control_0);
  1076. /* check whether it is not the end */
  1077. if (!own || *t_code == VXGE_HW_RING_T_CODE_FRM_DROP) {
  1078. vxge_assert((rxdp)->host_control !=
  1079. 0);
  1080. ++ring->cmpl_cnt;
  1081. vxge_hw_channel_dtr_complete(channel);
  1082. vxge_assert(*t_code != VXGE_HW_RING_RXD_T_CODE_UNUSED);
  1083. ring->stats->common_stats.usage_cnt++;
  1084. if (ring->stats->common_stats.usage_max <
  1085. ring->stats->common_stats.usage_cnt)
  1086. ring->stats->common_stats.usage_max =
  1087. ring->stats->common_stats.usage_cnt;
  1088. status = VXGE_HW_OK;
  1089. goto exit;
  1090. }
  1091. /* reset it. since we don't want to return
  1092. * garbage to the driver */
  1093. *rxdh = NULL;
  1094. status = VXGE_HW_INF_NO_MORE_COMPLETED_DESCRIPTORS;
  1095. exit:
  1096. return status;
  1097. }
  1098. /**
  1099. * vxge_hw_ring_handle_tcode - Handle transfer code.
  1100. * @ring: Handle to the ring object used for receive
  1101. * @rxdh: Descriptor handle.
  1102. * @t_code: One of the enumerated (and documented in the Titan user guide)
  1103. * "transfer codes".
  1104. *
  1105. * Handle descriptor's transfer code. The latter comes with each completed
  1106. * descriptor.
  1107. *
  1108. * Returns: one of the enum vxge_hw_status{} enumerated types.
  1109. * VXGE_HW_OK - for success.
  1110. * VXGE_HW_ERR_CRITICAL - when encounters critical error.
  1111. */
  1112. enum vxge_hw_status vxge_hw_ring_handle_tcode(
  1113. struct __vxge_hw_ring *ring, void *rxdh, u8 t_code)
  1114. {
  1115. struct __vxge_hw_channel *channel;
  1116. enum vxge_hw_status status = VXGE_HW_OK;
  1117. channel = &ring->channel;
  1118. /* If the t_code is not supported and if the
  1119. * t_code is other than 0x5 (unparseable packet
  1120. * such as unknown UPV6 header), Drop it !!!
  1121. */
  1122. if (t_code == VXGE_HW_RING_T_CODE_OK ||
  1123. t_code == VXGE_HW_RING_T_CODE_L3_PKT_ERR) {
  1124. status = VXGE_HW_OK;
  1125. goto exit;
  1126. }
  1127. if (t_code > VXGE_HW_RING_T_CODE_MULTI_ERR) {
  1128. status = VXGE_HW_ERR_INVALID_TCODE;
  1129. goto exit;
  1130. }
  1131. ring->stats->rxd_t_code_err_cnt[t_code]++;
  1132. exit:
  1133. return status;
  1134. }
  1135. /**
  1136. * __vxge_hw_non_offload_db_post - Post non offload doorbell
  1137. *
  1138. * @fifo: fifohandle
  1139. * @txdl_ptr: The starting location of the TxDL in host memory
  1140. * @num_txds: The highest TxD in this TxDL (0 to 255 means 1 to 256)
  1141. * @no_snoop: No snoop flags
  1142. *
  1143. * This function posts a non-offload doorbell to doorbell FIFO
  1144. *
  1145. */
  1146. static void __vxge_hw_non_offload_db_post(struct __vxge_hw_fifo *fifo,
  1147. u64 txdl_ptr, u32 num_txds, u32 no_snoop)
  1148. {
  1149. struct __vxge_hw_channel *channel;
  1150. channel = &fifo->channel;
  1151. writeq(VXGE_HW_NODBW_TYPE(VXGE_HW_NODBW_TYPE_NODBW) |
  1152. VXGE_HW_NODBW_LAST_TXD_NUMBER(num_txds) |
  1153. VXGE_HW_NODBW_GET_NO_SNOOP(no_snoop),
  1154. &fifo->nofl_db->control_0);
  1155. mmiowb();
  1156. writeq(txdl_ptr, &fifo->nofl_db->txdl_ptr);
  1157. mmiowb();
  1158. }
  1159. /**
  1160. * vxge_hw_fifo_free_txdl_count_get - returns the number of txdls available in
  1161. * the fifo
  1162. * @fifoh: Handle to the fifo object used for non offload send
  1163. */
  1164. u32 vxge_hw_fifo_free_txdl_count_get(struct __vxge_hw_fifo *fifoh)
  1165. {
  1166. return vxge_hw_channel_dtr_count(&fifoh->channel);
  1167. }
  1168. /**
  1169. * vxge_hw_fifo_txdl_reserve - Reserve fifo descriptor.
  1170. * @fifoh: Handle to the fifo object used for non offload send
  1171. * @txdlh: Reserved descriptor. On success HW fills this "out" parameter
  1172. * with a valid handle.
  1173. * @txdl_priv: Buffer to return the pointer to per txdl space
  1174. *
  1175. * Reserve a single TxDL (that is, fifo descriptor)
  1176. * for the subsequent filling-in by driver)
  1177. * and posting on the corresponding channel (@channelh)
  1178. * via vxge_hw_fifo_txdl_post().
  1179. *
  1180. * Note: it is the responsibility of driver to reserve multiple descriptors
  1181. * for lengthy (e.g., LSO) transmit operation. A single fifo descriptor
  1182. * carries up to configured number (fifo.max_frags) of contiguous buffers.
  1183. *
  1184. * Returns: VXGE_HW_OK - success;
  1185. * VXGE_HW_INF_OUT_OF_DESCRIPTORS - Currently no descriptors available
  1186. *
  1187. */
  1188. enum vxge_hw_status vxge_hw_fifo_txdl_reserve(
  1189. struct __vxge_hw_fifo *fifo,
  1190. void **txdlh, void **txdl_priv)
  1191. {
  1192. struct __vxge_hw_channel *channel;
  1193. enum vxge_hw_status status;
  1194. int i;
  1195. channel = &fifo->channel;
  1196. status = vxge_hw_channel_dtr_alloc(channel, txdlh);
  1197. if (status == VXGE_HW_OK) {
  1198. struct vxge_hw_fifo_txd *txdp =
  1199. (struct vxge_hw_fifo_txd *)*txdlh;
  1200. struct __vxge_hw_fifo_txdl_priv *priv;
  1201. priv = __vxge_hw_fifo_txdl_priv(fifo, txdp);
  1202. /* reset the TxDL's private */
  1203. priv->align_dma_offset = 0;
  1204. priv->align_vaddr_start = priv->align_vaddr;
  1205. priv->align_used_frags = 0;
  1206. priv->frags = 0;
  1207. priv->alloc_frags = fifo->config->max_frags;
  1208. priv->next_txdl_priv = NULL;
  1209. *txdl_priv = (void *)(size_t)txdp->host_control;
  1210. for (i = 0; i < fifo->config->max_frags; i++) {
  1211. txdp = ((struct vxge_hw_fifo_txd *)*txdlh) + i;
  1212. txdp->control_0 = txdp->control_1 = 0;
  1213. }
  1214. }
  1215. return status;
  1216. }
  1217. /**
  1218. * vxge_hw_fifo_txdl_buffer_set - Set transmit buffer pointer in the
  1219. * descriptor.
  1220. * @fifo: Handle to the fifo object used for non offload send
  1221. * @txdlh: Descriptor handle.
  1222. * @frag_idx: Index of the data buffer in the caller's scatter-gather list
  1223. * (of buffers).
  1224. * @dma_pointer: DMA address of the data buffer referenced by @frag_idx.
  1225. * @size: Size of the data buffer (in bytes).
  1226. *
  1227. * This API is part of the preparation of the transmit descriptor for posting
  1228. * (via vxge_hw_fifo_txdl_post()). The related "preparation" APIs include
  1229. * vxge_hw_fifo_txdl_mss_set() and vxge_hw_fifo_txdl_cksum_set_bits().
  1230. * All three APIs fill in the fields of the fifo descriptor,
  1231. * in accordance with the Titan specification.
  1232. *
  1233. */
  1234. void vxge_hw_fifo_txdl_buffer_set(struct __vxge_hw_fifo *fifo,
  1235. void *txdlh, u32 frag_idx,
  1236. dma_addr_t dma_pointer, u32 size)
  1237. {
  1238. struct __vxge_hw_fifo_txdl_priv *txdl_priv;
  1239. struct vxge_hw_fifo_txd *txdp, *txdp_last;
  1240. struct __vxge_hw_channel *channel;
  1241. channel = &fifo->channel;
  1242. txdl_priv = __vxge_hw_fifo_txdl_priv(fifo, txdlh);
  1243. txdp = (struct vxge_hw_fifo_txd *)txdlh + txdl_priv->frags;
  1244. if (frag_idx != 0)
  1245. txdp->control_0 = txdp->control_1 = 0;
  1246. else {
  1247. txdp->control_0 |= VXGE_HW_FIFO_TXD_GATHER_CODE(
  1248. VXGE_HW_FIFO_TXD_GATHER_CODE_FIRST);
  1249. txdp->control_1 |= fifo->interrupt_type;
  1250. txdp->control_1 |= VXGE_HW_FIFO_TXD_INT_NUMBER(
  1251. fifo->tx_intr_num);
  1252. if (txdl_priv->frags) {
  1253. txdp_last = (struct vxge_hw_fifo_txd *)txdlh +
  1254. (txdl_priv->frags - 1);
  1255. txdp_last->control_0 |= VXGE_HW_FIFO_TXD_GATHER_CODE(
  1256. VXGE_HW_FIFO_TXD_GATHER_CODE_LAST);
  1257. }
  1258. }
  1259. vxge_assert(frag_idx < txdl_priv->alloc_frags);
  1260. txdp->buffer_pointer = (u64)dma_pointer;
  1261. txdp->control_0 |= VXGE_HW_FIFO_TXD_BUFFER_SIZE(size);
  1262. fifo->stats->total_buffers++;
  1263. txdl_priv->frags++;
  1264. }
  1265. /**
  1266. * vxge_hw_fifo_txdl_post - Post descriptor on the fifo channel.
  1267. * @fifo: Handle to the fifo object used for non offload send
  1268. * @txdlh: Descriptor obtained via vxge_hw_fifo_txdl_reserve()
  1269. * @frags: Number of contiguous buffers that are part of a single
  1270. * transmit operation.
  1271. *
  1272. * Post descriptor on the 'fifo' type channel for transmission.
  1273. * Prior to posting the descriptor should be filled in accordance with
  1274. * Host/Titan interface specification for a given service (LL, etc.).
  1275. *
  1276. */
  1277. void vxge_hw_fifo_txdl_post(struct __vxge_hw_fifo *fifo, void *txdlh)
  1278. {
  1279. struct __vxge_hw_fifo_txdl_priv *txdl_priv;
  1280. struct vxge_hw_fifo_txd *txdp_last;
  1281. struct vxge_hw_fifo_txd *txdp_first;
  1282. struct __vxge_hw_channel *channel;
  1283. channel = &fifo->channel;
  1284. txdl_priv = __vxge_hw_fifo_txdl_priv(fifo, txdlh);
  1285. txdp_first = txdlh;
  1286. txdp_last = (struct vxge_hw_fifo_txd *)txdlh + (txdl_priv->frags - 1);
  1287. txdp_last->control_0 |=
  1288. VXGE_HW_FIFO_TXD_GATHER_CODE(VXGE_HW_FIFO_TXD_GATHER_CODE_LAST);
  1289. txdp_first->control_0 |= VXGE_HW_FIFO_TXD_LIST_OWN_ADAPTER;
  1290. vxge_hw_channel_dtr_post(&fifo->channel, txdlh);
  1291. __vxge_hw_non_offload_db_post(fifo,
  1292. (u64)txdl_priv->dma_addr,
  1293. txdl_priv->frags - 1,
  1294. fifo->no_snoop_bits);
  1295. fifo->stats->total_posts++;
  1296. fifo->stats->common_stats.usage_cnt++;
  1297. if (fifo->stats->common_stats.usage_max <
  1298. fifo->stats->common_stats.usage_cnt)
  1299. fifo->stats->common_stats.usage_max =
  1300. fifo->stats->common_stats.usage_cnt;
  1301. }
  1302. /**
  1303. * vxge_hw_fifo_txdl_next_completed - Retrieve next completed descriptor.
  1304. * @fifo: Handle to the fifo object used for non offload send
  1305. * @txdlh: Descriptor handle. Returned by HW.
  1306. * @t_code: Transfer code, as per Titan User Guide,
  1307. * Transmit Descriptor Format.
  1308. * Returned by HW.
  1309. *
  1310. * Retrieve the _next_ completed descriptor.
  1311. * HW uses channel callback (*vxge_hw_channel_callback_f) to notifiy
  1312. * driver of new completed descriptors. After that
  1313. * the driver can use vxge_hw_fifo_txdl_next_completed to retrieve the rest
  1314. * completions (the very first completion is passed by HW via
  1315. * vxge_hw_channel_callback_f).
  1316. *
  1317. * Implementation-wise, the driver is free to call
  1318. * vxge_hw_fifo_txdl_next_completed either immediately from inside the
  1319. * channel callback, or in a deferred fashion and separate (from HW)
  1320. * context.
  1321. *
  1322. * Non-zero @t_code means failure to process the descriptor.
  1323. * The failure could happen, for instance, when the link is
  1324. * down, in which case Titan completes the descriptor because it
  1325. * is not able to send the data out.
  1326. *
  1327. * For details please refer to Titan User Guide.
  1328. *
  1329. * Returns: VXGE_HW_OK - success.
  1330. * VXGE_HW_INF_NO_MORE_COMPLETED_DESCRIPTORS - No completed descriptors
  1331. * are currently available for processing.
  1332. *
  1333. */
  1334. enum vxge_hw_status vxge_hw_fifo_txdl_next_completed(
  1335. struct __vxge_hw_fifo *fifo, void **txdlh,
  1336. enum vxge_hw_fifo_tcode *t_code)
  1337. {
  1338. struct __vxge_hw_channel *channel;
  1339. struct vxge_hw_fifo_txd *txdp;
  1340. enum vxge_hw_status status = VXGE_HW_OK;
  1341. channel = &fifo->channel;
  1342. vxge_hw_channel_dtr_try_complete(channel, txdlh);
  1343. txdp = *txdlh;
  1344. if (txdp == NULL) {
  1345. status = VXGE_HW_INF_NO_MORE_COMPLETED_DESCRIPTORS;
  1346. goto exit;
  1347. }
  1348. /* check whether host owns it */
  1349. if (!(txdp->control_0 & VXGE_HW_FIFO_TXD_LIST_OWN_ADAPTER)) {
  1350. vxge_assert(txdp->host_control != 0);
  1351. vxge_hw_channel_dtr_complete(channel);
  1352. *t_code = (u8)VXGE_HW_FIFO_TXD_T_CODE_GET(txdp->control_0);
  1353. if (fifo->stats->common_stats.usage_cnt > 0)
  1354. fifo->stats->common_stats.usage_cnt--;
  1355. status = VXGE_HW_OK;
  1356. goto exit;
  1357. }
  1358. /* no more completions */
  1359. *txdlh = NULL;
  1360. status = VXGE_HW_INF_NO_MORE_COMPLETED_DESCRIPTORS;
  1361. exit:
  1362. return status;
  1363. }
  1364. /**
  1365. * vxge_hw_fifo_handle_tcode - Handle transfer code.
  1366. * @fifo: Handle to the fifo object used for non offload send
  1367. * @txdlh: Descriptor handle.
  1368. * @t_code: One of the enumerated (and documented in the Titan user guide)
  1369. * "transfer codes".
  1370. *
  1371. * Handle descriptor's transfer code. The latter comes with each completed
  1372. * descriptor.
  1373. *
  1374. * Returns: one of the enum vxge_hw_status{} enumerated types.
  1375. * VXGE_HW_OK - for success.
  1376. * VXGE_HW_ERR_CRITICAL - when encounters critical error.
  1377. */
  1378. enum vxge_hw_status vxge_hw_fifo_handle_tcode(struct __vxge_hw_fifo *fifo,
  1379. void *txdlh,
  1380. enum vxge_hw_fifo_tcode t_code)
  1381. {
  1382. struct __vxge_hw_channel *channel;
  1383. enum vxge_hw_status status = VXGE_HW_OK;
  1384. channel = &fifo->channel;
  1385. if (((t_code & 0x7) < 0) || ((t_code & 0x7) > 0x4)) {
  1386. status = VXGE_HW_ERR_INVALID_TCODE;
  1387. goto exit;
  1388. }
  1389. fifo->stats->txd_t_code_err_cnt[t_code]++;
  1390. exit:
  1391. return status;
  1392. }
  1393. /**
  1394. * vxge_hw_fifo_txdl_free - Free descriptor.
  1395. * @fifo: Handle to the fifo object used for non offload send
  1396. * @txdlh: Descriptor handle.
  1397. *
  1398. * Free the reserved descriptor. This operation is "symmetrical" to
  1399. * vxge_hw_fifo_txdl_reserve. The "free-ing" completes the descriptor's
  1400. * lifecycle.
  1401. *
  1402. * After free-ing (see vxge_hw_fifo_txdl_free()) the descriptor again can
  1403. * be:
  1404. *
  1405. * - reserved (vxge_hw_fifo_txdl_reserve);
  1406. *
  1407. * - posted (vxge_hw_fifo_txdl_post);
  1408. *
  1409. * - completed (vxge_hw_fifo_txdl_next_completed);
  1410. *
  1411. * - and recycled again (vxge_hw_fifo_txdl_free).
  1412. *
  1413. * For alternative state transitions and more details please refer to
  1414. * the design doc.
  1415. *
  1416. */
  1417. void vxge_hw_fifo_txdl_free(struct __vxge_hw_fifo *fifo, void *txdlh)
  1418. {
  1419. struct __vxge_hw_fifo_txdl_priv *txdl_priv;
  1420. u32 max_frags;
  1421. struct __vxge_hw_channel *channel;
  1422. channel = &fifo->channel;
  1423. txdl_priv = __vxge_hw_fifo_txdl_priv(fifo,
  1424. (struct vxge_hw_fifo_txd *)txdlh);
  1425. max_frags = fifo->config->max_frags;
  1426. vxge_hw_channel_dtr_free(channel, txdlh);
  1427. }
  1428. /**
  1429. * vxge_hw_vpath_mac_addr_add - Add the mac address entry for this vpath
  1430. * to MAC address table.
  1431. * @vp: Vpath handle.
  1432. * @macaddr: MAC address to be added for this vpath into the list
  1433. * @macaddr_mask: MAC address mask for macaddr
  1434. * @duplicate_mode: Duplicate MAC address add mode. Please see
  1435. * enum vxge_hw_vpath_mac_addr_add_mode{}
  1436. *
  1437. * Adds the given mac address and mac address mask into the list for this
  1438. * vpath.
  1439. * see also: vxge_hw_vpath_mac_addr_delete, vxge_hw_vpath_mac_addr_get and
  1440. * vxge_hw_vpath_mac_addr_get_next
  1441. *
  1442. */
  1443. enum vxge_hw_status
  1444. vxge_hw_vpath_mac_addr_add(
  1445. struct __vxge_hw_vpath_handle *vp,
  1446. u8 (macaddr)[ETH_ALEN],
  1447. u8 (macaddr_mask)[ETH_ALEN],
  1448. enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode)
  1449. {
  1450. u32 i;
  1451. u64 data1 = 0ULL;
  1452. u64 data2 = 0ULL;
  1453. enum vxge_hw_status status = VXGE_HW_OK;
  1454. if (vp == NULL) {
  1455. status = VXGE_HW_ERR_INVALID_HANDLE;
  1456. goto exit;
  1457. }
  1458. for (i = 0; i < ETH_ALEN; i++) {
  1459. data1 <<= 8;
  1460. data1 |= (u8)macaddr[i];
  1461. data2 <<= 8;
  1462. data2 |= (u8)macaddr_mask[i];
  1463. }
  1464. switch (duplicate_mode) {
  1465. case VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE:
  1466. i = 0;
  1467. break;
  1468. case VXGE_HW_VPATH_MAC_ADDR_DISCARD_DUPLICATE:
  1469. i = 1;
  1470. break;
  1471. case VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE:
  1472. i = 2;
  1473. break;
  1474. default:
  1475. i = 0;
  1476. break;
  1477. }
  1478. status = __vxge_hw_vpath_rts_table_set(vp,
  1479. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_ADD_ENTRY,
  1480. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA,
  1481. 0,
  1482. VXGE_HW_RTS_ACCESS_STEER_DATA0_DA_MAC_ADDR(data1),
  1483. VXGE_HW_RTS_ACCESS_STEER_DATA1_DA_MAC_ADDR_MASK(data2)|
  1484. VXGE_HW_RTS_ACCESS_STEER_DATA1_DA_MAC_ADDR_MODE(i));
  1485. exit:
  1486. return status;
  1487. }
  1488. /**
  1489. * vxge_hw_vpath_mac_addr_get - Get the first mac address entry for this vpath
  1490. * from MAC address table.
  1491. * @vp: Vpath handle.
  1492. * @macaddr: First MAC address entry for this vpath in the list
  1493. * @macaddr_mask: MAC address mask for macaddr
  1494. *
  1495. * Returns the first mac address and mac address mask in the list for this
  1496. * vpath.
  1497. * see also: vxge_hw_vpath_mac_addr_get_next
  1498. *
  1499. */
  1500. enum vxge_hw_status
  1501. vxge_hw_vpath_mac_addr_get(
  1502. struct __vxge_hw_vpath_handle *vp,
  1503. u8 (macaddr)[ETH_ALEN],
  1504. u8 (macaddr_mask)[ETH_ALEN])
  1505. {
  1506. u32 i;
  1507. u64 data1 = 0ULL;
  1508. u64 data2 = 0ULL;
  1509. enum vxge_hw_status status = VXGE_HW_OK;
  1510. if (vp == NULL) {
  1511. status = VXGE_HW_ERR_INVALID_HANDLE;
  1512. goto exit;
  1513. }
  1514. status = __vxge_hw_vpath_rts_table_get(vp,
  1515. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LIST_FIRST_ENTRY,
  1516. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA,
  1517. 0, &data1, &data2);
  1518. if (status != VXGE_HW_OK)
  1519. goto exit;
  1520. data1 = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_DA_MAC_ADDR(data1);
  1521. data2 = VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_DA_MAC_ADDR_MASK(data2);
  1522. for (i = ETH_ALEN; i > 0; i--) {
  1523. macaddr[i-1] = (u8)(data1 & 0xFF);
  1524. data1 >>= 8;
  1525. macaddr_mask[i-1] = (u8)(data2 & 0xFF);
  1526. data2 >>= 8;
  1527. }
  1528. exit:
  1529. return status;
  1530. }
  1531. /**
  1532. * vxge_hw_vpath_mac_addr_get_next - Get the next mac address entry for this
  1533. * vpath
  1534. * from MAC address table.
  1535. * @vp: Vpath handle.
  1536. * @macaddr: Next MAC address entry for this vpath in the list
  1537. * @macaddr_mask: MAC address mask for macaddr
  1538. *
  1539. * Returns the next mac address and mac address mask in the list for this
  1540. * vpath.
  1541. * see also: vxge_hw_vpath_mac_addr_get
  1542. *
  1543. */
  1544. enum vxge_hw_status
  1545. vxge_hw_vpath_mac_addr_get_next(
  1546. struct __vxge_hw_vpath_handle *vp,
  1547. u8 (macaddr)[ETH_ALEN],
  1548. u8 (macaddr_mask)[ETH_ALEN])
  1549. {
  1550. u32 i;
  1551. u64 data1 = 0ULL;
  1552. u64 data2 = 0ULL;
  1553. enum vxge_hw_status status = VXGE_HW_OK;
  1554. if (vp == NULL) {
  1555. status = VXGE_HW_ERR_INVALID_HANDLE;
  1556. goto exit;
  1557. }
  1558. status = __vxge_hw_vpath_rts_table_get(vp,
  1559. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LIST_NEXT_ENTRY,
  1560. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA,
  1561. 0, &data1, &data2);
  1562. if (status != VXGE_HW_OK)
  1563. goto exit;
  1564. data1 = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_DA_MAC_ADDR(data1);
  1565. data2 = VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_DA_MAC_ADDR_MASK(data2);
  1566. for (i = ETH_ALEN; i > 0; i--) {
  1567. macaddr[i-1] = (u8)(data1 & 0xFF);
  1568. data1 >>= 8;
  1569. macaddr_mask[i-1] = (u8)(data2 & 0xFF);
  1570. data2 >>= 8;
  1571. }
  1572. exit:
  1573. return status;
  1574. }
  1575. /**
  1576. * vxge_hw_vpath_mac_addr_delete - Delete the mac address entry for this vpath
  1577. * to MAC address table.
  1578. * @vp: Vpath handle.
  1579. * @macaddr: MAC address to be added for this vpath into the list
  1580. * @macaddr_mask: MAC address mask for macaddr
  1581. *
  1582. * Delete the given mac address and mac address mask into the list for this
  1583. * vpath.
  1584. * see also: vxge_hw_vpath_mac_addr_add, vxge_hw_vpath_mac_addr_get and
  1585. * vxge_hw_vpath_mac_addr_get_next
  1586. *
  1587. */
  1588. enum vxge_hw_status
  1589. vxge_hw_vpath_mac_addr_delete(
  1590. struct __vxge_hw_vpath_handle *vp,
  1591. u8 (macaddr)[ETH_ALEN],
  1592. u8 (macaddr_mask)[ETH_ALEN])
  1593. {
  1594. u32 i;
  1595. u64 data1 = 0ULL;
  1596. u64 data2 = 0ULL;
  1597. enum vxge_hw_status status = VXGE_HW_OK;
  1598. if (vp == NULL) {
  1599. status = VXGE_HW_ERR_INVALID_HANDLE;
  1600. goto exit;
  1601. }
  1602. for (i = 0; i < ETH_ALEN; i++) {
  1603. data1 <<= 8;
  1604. data1 |= (u8)macaddr[i];
  1605. data2 <<= 8;
  1606. data2 |= (u8)macaddr_mask[i];
  1607. }
  1608. status = __vxge_hw_vpath_rts_table_set(vp,
  1609. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_DELETE_ENTRY,
  1610. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA,
  1611. 0,
  1612. VXGE_HW_RTS_ACCESS_STEER_DATA0_DA_MAC_ADDR(data1),
  1613. VXGE_HW_RTS_ACCESS_STEER_DATA1_DA_MAC_ADDR_MASK(data2));
  1614. exit:
  1615. return status;
  1616. }
  1617. /**
  1618. * vxge_hw_vpath_vid_add - Add the vlan id entry for this vpath
  1619. * to vlan id table.
  1620. * @vp: Vpath handle.
  1621. * @vid: vlan id to be added for this vpath into the list
  1622. *
  1623. * Adds the given vlan id into the list for this vpath.
  1624. * see also: vxge_hw_vpath_vid_delete
  1625. *
  1626. */
  1627. enum vxge_hw_status
  1628. vxge_hw_vpath_vid_add(struct __vxge_hw_vpath_handle *vp, u64 vid)
  1629. {
  1630. enum vxge_hw_status status = VXGE_HW_OK;
  1631. if (vp == NULL) {
  1632. status = VXGE_HW_ERR_INVALID_HANDLE;
  1633. goto exit;
  1634. }
  1635. status = __vxge_hw_vpath_rts_table_set(vp,
  1636. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_ADD_ENTRY,
  1637. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_VID,
  1638. 0, VXGE_HW_RTS_ACCESS_STEER_DATA0_VLAN_ID(vid), 0);
  1639. exit:
  1640. return status;
  1641. }
  1642. /**
  1643. * vxge_hw_vpath_vid_delete - Delete the vlan id entry for this vpath
  1644. * to vlan id table.
  1645. * @vp: Vpath handle.
  1646. * @vid: vlan id to be added for this vpath into the list
  1647. *
  1648. * Adds the given vlan id into the list for this vpath.
  1649. * see also: vxge_hw_vpath_vid_add
  1650. *
  1651. */
  1652. enum vxge_hw_status
  1653. vxge_hw_vpath_vid_delete(struct __vxge_hw_vpath_handle *vp, u64 vid)
  1654. {
  1655. enum vxge_hw_status status = VXGE_HW_OK;
  1656. if (vp == NULL) {
  1657. status = VXGE_HW_ERR_INVALID_HANDLE;
  1658. goto exit;
  1659. }
  1660. status = __vxge_hw_vpath_rts_table_set(vp,
  1661. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_DELETE_ENTRY,
  1662. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_VID,
  1663. 0, VXGE_HW_RTS_ACCESS_STEER_DATA0_VLAN_ID(vid), 0);
  1664. exit:
  1665. return status;
  1666. }
  1667. /**
  1668. * vxge_hw_vpath_promisc_enable - Enable promiscuous mode.
  1669. * @vp: Vpath handle.
  1670. *
  1671. * Enable promiscuous mode of Titan-e operation.
  1672. *
  1673. * See also: vxge_hw_vpath_promisc_disable().
  1674. */
  1675. enum vxge_hw_status vxge_hw_vpath_promisc_enable(
  1676. struct __vxge_hw_vpath_handle *vp)
  1677. {
  1678. u64 val64;
  1679. struct __vxge_hw_virtualpath *vpath;
  1680. enum vxge_hw_status status = VXGE_HW_OK;
  1681. if ((vp == NULL) || (vp->vpath->ringh == NULL)) {
  1682. status = VXGE_HW_ERR_INVALID_HANDLE;
  1683. goto exit;
  1684. }
  1685. vpath = vp->vpath;
  1686. /* Enable promiscuous mode for function 0 only */
  1687. if (!(vpath->hldev->access_rights &
  1688. VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM))
  1689. return VXGE_HW_OK;
  1690. val64 = readq(&vpath->vp_reg->rxmac_vcfg0);
  1691. if (!(val64 & VXGE_HW_RXMAC_VCFG0_UCAST_ALL_ADDR_EN)) {
  1692. val64 |= VXGE_HW_RXMAC_VCFG0_UCAST_ALL_ADDR_EN |
  1693. VXGE_HW_RXMAC_VCFG0_MCAST_ALL_ADDR_EN |
  1694. VXGE_HW_RXMAC_VCFG0_BCAST_EN |
  1695. VXGE_HW_RXMAC_VCFG0_ALL_VID_EN;
  1696. writeq(val64, &vpath->vp_reg->rxmac_vcfg0);
  1697. }
  1698. exit:
  1699. return status;
  1700. }
  1701. /**
  1702. * vxge_hw_vpath_promisc_disable - Disable promiscuous mode.
  1703. * @vp: Vpath handle.
  1704. *
  1705. * Disable promiscuous mode of Titan-e operation.
  1706. *
  1707. * See also: vxge_hw_vpath_promisc_enable().
  1708. */
  1709. enum vxge_hw_status vxge_hw_vpath_promisc_disable(
  1710. struct __vxge_hw_vpath_handle *vp)
  1711. {
  1712. u64 val64;
  1713. struct __vxge_hw_virtualpath *vpath;
  1714. enum vxge_hw_status status = VXGE_HW_OK;
  1715. if ((vp == NULL) || (vp->vpath->ringh == NULL)) {
  1716. status = VXGE_HW_ERR_INVALID_HANDLE;
  1717. goto exit;
  1718. }
  1719. vpath = vp->vpath;
  1720. val64 = readq(&vpath->vp_reg->rxmac_vcfg0);
  1721. if (val64 & VXGE_HW_RXMAC_VCFG0_UCAST_ALL_ADDR_EN) {
  1722. val64 &= ~(VXGE_HW_RXMAC_VCFG0_UCAST_ALL_ADDR_EN |
  1723. VXGE_HW_RXMAC_VCFG0_MCAST_ALL_ADDR_EN |
  1724. VXGE_HW_RXMAC_VCFG0_ALL_VID_EN);
  1725. writeq(val64, &vpath->vp_reg->rxmac_vcfg0);
  1726. }
  1727. exit:
  1728. return status;
  1729. }
  1730. /*
  1731. * vxge_hw_vpath_bcast_enable - Enable broadcast
  1732. * @vp: Vpath handle.
  1733. *
  1734. * Enable receiving broadcasts.
  1735. */
  1736. enum vxge_hw_status vxge_hw_vpath_bcast_enable(
  1737. struct __vxge_hw_vpath_handle *vp)
  1738. {
  1739. u64 val64;
  1740. struct __vxge_hw_virtualpath *vpath;
  1741. enum vxge_hw_status status = VXGE_HW_OK;
  1742. if ((vp == NULL) || (vp->vpath->ringh == NULL)) {
  1743. status = VXGE_HW_ERR_INVALID_HANDLE;
  1744. goto exit;
  1745. }
  1746. vpath = vp->vpath;
  1747. val64 = readq(&vpath->vp_reg->rxmac_vcfg0);
  1748. if (!(val64 & VXGE_HW_RXMAC_VCFG0_BCAST_EN)) {
  1749. val64 |= VXGE_HW_RXMAC_VCFG0_BCAST_EN;
  1750. writeq(val64, &vpath->vp_reg->rxmac_vcfg0);
  1751. }
  1752. exit:
  1753. return status;
  1754. }
  1755. /**
  1756. * vxge_hw_vpath_mcast_enable - Enable multicast addresses.
  1757. * @vp: Vpath handle.
  1758. *
  1759. * Enable Titan-e multicast addresses.
  1760. * Returns: VXGE_HW_OK on success.
  1761. *
  1762. */
  1763. enum vxge_hw_status vxge_hw_vpath_mcast_enable(
  1764. struct __vxge_hw_vpath_handle *vp)
  1765. {
  1766. u64 val64;
  1767. struct __vxge_hw_virtualpath *vpath;
  1768. enum vxge_hw_status status = VXGE_HW_OK;
  1769. if ((vp == NULL) || (vp->vpath->ringh == NULL)) {
  1770. status = VXGE_HW_ERR_INVALID_HANDLE;
  1771. goto exit;
  1772. }
  1773. vpath = vp->vpath;
  1774. val64 = readq(&vpath->vp_reg->rxmac_vcfg0);
  1775. if (!(val64 & VXGE_HW_RXMAC_VCFG0_MCAST_ALL_ADDR_EN)) {
  1776. val64 |= VXGE_HW_RXMAC_VCFG0_MCAST_ALL_ADDR_EN;
  1777. writeq(val64, &vpath->vp_reg->rxmac_vcfg0);
  1778. }
  1779. exit:
  1780. return status;
  1781. }
  1782. /**
  1783. * vxge_hw_vpath_mcast_disable - Disable multicast addresses.
  1784. * @vp: Vpath handle.
  1785. *
  1786. * Disable Titan-e multicast addresses.
  1787. * Returns: VXGE_HW_OK - success.
  1788. * VXGE_HW_ERR_INVALID_HANDLE - Invalid handle
  1789. *
  1790. */
  1791. enum vxge_hw_status
  1792. vxge_hw_vpath_mcast_disable(struct __vxge_hw_vpath_handle *vp)
  1793. {
  1794. u64 val64;
  1795. struct __vxge_hw_virtualpath *vpath;
  1796. enum vxge_hw_status status = VXGE_HW_OK;
  1797. if ((vp == NULL) || (vp->vpath->ringh == NULL)) {
  1798. status = VXGE_HW_ERR_INVALID_HANDLE;
  1799. goto exit;
  1800. }
  1801. vpath = vp->vpath;
  1802. val64 = readq(&vpath->vp_reg->rxmac_vcfg0);
  1803. if (val64 & VXGE_HW_RXMAC_VCFG0_MCAST_ALL_ADDR_EN) {
  1804. val64 &= ~VXGE_HW_RXMAC_VCFG0_MCAST_ALL_ADDR_EN;
  1805. writeq(val64, &vpath->vp_reg->rxmac_vcfg0);
  1806. }
  1807. exit:
  1808. return status;
  1809. }
  1810. /*
  1811. * vxge_hw_vpath_alarm_process - Process Alarms.
  1812. * @vpath: Virtual Path.
  1813. * @skip_alarms: Do not clear the alarms
  1814. *
  1815. * Process vpath alarms.
  1816. *
  1817. */
  1818. enum vxge_hw_status vxge_hw_vpath_alarm_process(
  1819. struct __vxge_hw_vpath_handle *vp,
  1820. u32 skip_alarms)
  1821. {
  1822. enum vxge_hw_status status = VXGE_HW_OK;
  1823. if (vp == NULL) {
  1824. status = VXGE_HW_ERR_INVALID_HANDLE;
  1825. goto exit;
  1826. }
  1827. status = __vxge_hw_vpath_alarm_process(vp->vpath, skip_alarms);
  1828. exit:
  1829. return status;
  1830. }
  1831. /**
  1832. * vxge_hw_vpath_msix_set - Associate MSIX vectors with TIM interrupts and
  1833. * alrms
  1834. * @vp: Virtual Path handle.
  1835. * @tim_msix_id: MSIX vectors associated with VXGE_HW_MAX_INTR_PER_VP number of
  1836. * interrupts(Can be repeated). If fifo or ring are not enabled
  1837. * the MSIX vector for that should be set to 0
  1838. * @alarm_msix_id: MSIX vector for alarm.
  1839. *
  1840. * This API will associate a given MSIX vector numbers with the four TIM
  1841. * interrupts and alarm interrupt.
  1842. */
  1843. void
  1844. vxge_hw_vpath_msix_set(struct __vxge_hw_vpath_handle *vp, int *tim_msix_id,
  1845. int alarm_msix_id)
  1846. {
  1847. u64 val64;
  1848. struct __vxge_hw_virtualpath *vpath = vp->vpath;
  1849. struct vxge_hw_vpath_reg __iomem *vp_reg = vpath->vp_reg;
  1850. u32 vp_id = vp->vpath->vp_id;
  1851. val64 = VXGE_HW_INTERRUPT_CFG0_GROUP0_MSIX_FOR_TXTI(
  1852. (vp_id * 4) + tim_msix_id[0]) |
  1853. VXGE_HW_INTERRUPT_CFG0_GROUP1_MSIX_FOR_TXTI(
  1854. (vp_id * 4) + tim_msix_id[1]);
  1855. writeq(val64, &vp_reg->interrupt_cfg0);
  1856. writeq(VXGE_HW_INTERRUPT_CFG2_ALARM_MAP_TO_MSG(
  1857. (vpath->hldev->first_vp_id * 4) + alarm_msix_id),
  1858. &vp_reg->interrupt_cfg2);
  1859. if (vpath->hldev->config.intr_mode ==
  1860. VXGE_HW_INTR_MODE_MSIX_ONE_SHOT) {
  1861. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(
  1862. VXGE_HW_ONE_SHOT_VECT0_EN_ONE_SHOT_VECT0_EN,
  1863. 0, 32), &vp_reg->one_shot_vect0_en);
  1864. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(
  1865. VXGE_HW_ONE_SHOT_VECT1_EN_ONE_SHOT_VECT1_EN,
  1866. 0, 32), &vp_reg->one_shot_vect1_en);
  1867. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(
  1868. VXGE_HW_ONE_SHOT_VECT2_EN_ONE_SHOT_VECT2_EN,
  1869. 0, 32), &vp_reg->one_shot_vect2_en);
  1870. }
  1871. }
  1872. /**
  1873. * vxge_hw_vpath_msix_mask - Mask MSIX Vector.
  1874. * @vp: Virtual Path handle.
  1875. * @msix_id: MSIX ID
  1876. *
  1877. * The function masks the msix interrupt for the given msix_id
  1878. *
  1879. * Returns: 0,
  1880. * Otherwise, VXGE_HW_ERR_WRONG_IRQ if the msix index is out of range
  1881. * status.
  1882. * See also:
  1883. */
  1884. void
  1885. vxge_hw_vpath_msix_mask(struct __vxge_hw_vpath_handle *vp, int msix_id)
  1886. {
  1887. struct __vxge_hw_device *hldev = vp->vpath->hldev;
  1888. __vxge_hw_pio_mem_write32_upper(
  1889. (u32) vxge_bVALn(vxge_mBIT(msix_id >> 2), 0, 32),
  1890. &hldev->common_reg->set_msix_mask_vect[msix_id % 4]);
  1891. }
  1892. /**
  1893. * vxge_hw_vpath_msix_clear - Clear MSIX Vector.
  1894. * @vp: Virtual Path handle.
  1895. * @msix_id: MSI ID
  1896. *
  1897. * The function clears the msix interrupt for the given msix_id
  1898. *
  1899. * Returns: 0,
  1900. * Otherwise, VXGE_HW_ERR_WRONG_IRQ if the msix index is out of range
  1901. * status.
  1902. * See also:
  1903. */
  1904. void vxge_hw_vpath_msix_clear(struct __vxge_hw_vpath_handle *vp, int msix_id)
  1905. {
  1906. struct __vxge_hw_device *hldev = vp->vpath->hldev;
  1907. if ((hldev->config.intr_mode == VXGE_HW_INTR_MODE_MSIX_ONE_SHOT))
  1908. __vxge_hw_pio_mem_write32_upper(
  1909. (u32) vxge_bVALn(vxge_mBIT((msix_id >> 2)), 0, 32),
  1910. &hldev->common_reg->clr_msix_one_shot_vec[msix_id % 4]);
  1911. else
  1912. __vxge_hw_pio_mem_write32_upper(
  1913. (u32) vxge_bVALn(vxge_mBIT((msix_id >> 2)), 0, 32),
  1914. &hldev->common_reg->clear_msix_mask_vect[msix_id % 4]);
  1915. }
  1916. /**
  1917. * vxge_hw_vpath_msix_unmask - Unmask the MSIX Vector.
  1918. * @vp: Virtual Path handle.
  1919. * @msix_id: MSI ID
  1920. *
  1921. * The function unmasks the msix interrupt for the given msix_id
  1922. *
  1923. * Returns: 0,
  1924. * Otherwise, VXGE_HW_ERR_WRONG_IRQ if the msix index is out of range
  1925. * status.
  1926. * See also:
  1927. */
  1928. void
  1929. vxge_hw_vpath_msix_unmask(struct __vxge_hw_vpath_handle *vp, int msix_id)
  1930. {
  1931. struct __vxge_hw_device *hldev = vp->vpath->hldev;
  1932. __vxge_hw_pio_mem_write32_upper(
  1933. (u32)vxge_bVALn(vxge_mBIT(msix_id >> 2), 0, 32),
  1934. &hldev->common_reg->clear_msix_mask_vect[msix_id%4]);
  1935. }
  1936. /**
  1937. * vxge_hw_vpath_inta_mask_tx_rx - Mask Tx and Rx interrupts.
  1938. * @vp: Virtual Path handle.
  1939. *
  1940. * Mask Tx and Rx vpath interrupts.
  1941. *
  1942. * See also: vxge_hw_vpath_inta_mask_tx_rx()
  1943. */
  1944. void vxge_hw_vpath_inta_mask_tx_rx(struct __vxge_hw_vpath_handle *vp)
  1945. {
  1946. u64 tim_int_mask0[4] = {[0 ...3] = 0};
  1947. u32 tim_int_mask1[4] = {[0 ...3] = 0};
  1948. u64 val64;
  1949. struct __vxge_hw_device *hldev = vp->vpath->hldev;
  1950. VXGE_HW_DEVICE_TIM_INT_MASK_SET(tim_int_mask0,
  1951. tim_int_mask1, vp->vpath->vp_id);
  1952. val64 = readq(&hldev->common_reg->tim_int_mask0);
  1953. if ((tim_int_mask0[VXGE_HW_VPATH_INTR_TX] != 0) ||
  1954. (tim_int_mask0[VXGE_HW_VPATH_INTR_RX] != 0)) {
  1955. writeq((tim_int_mask0[VXGE_HW_VPATH_INTR_TX] |
  1956. tim_int_mask0[VXGE_HW_VPATH_INTR_RX] | val64),
  1957. &hldev->common_reg->tim_int_mask0);
  1958. }
  1959. val64 = readl(&hldev->common_reg->tim_int_mask1);
  1960. if ((tim_int_mask1[VXGE_HW_VPATH_INTR_TX] != 0) ||
  1961. (tim_int_mask1[VXGE_HW_VPATH_INTR_RX] != 0)) {
  1962. __vxge_hw_pio_mem_write32_upper(
  1963. (tim_int_mask1[VXGE_HW_VPATH_INTR_TX] |
  1964. tim_int_mask1[VXGE_HW_VPATH_INTR_RX] | val64),
  1965. &hldev->common_reg->tim_int_mask1);
  1966. }
  1967. }
  1968. /**
  1969. * vxge_hw_vpath_inta_unmask_tx_rx - Unmask Tx and Rx interrupts.
  1970. * @vp: Virtual Path handle.
  1971. *
  1972. * Unmask Tx and Rx vpath interrupts.
  1973. *
  1974. * See also: vxge_hw_vpath_inta_mask_tx_rx()
  1975. */
  1976. void vxge_hw_vpath_inta_unmask_tx_rx(struct __vxge_hw_vpath_handle *vp)
  1977. {
  1978. u64 tim_int_mask0[4] = {[0 ...3] = 0};
  1979. u32 tim_int_mask1[4] = {[0 ...3] = 0};
  1980. u64 val64;
  1981. struct __vxge_hw_device *hldev = vp->vpath->hldev;
  1982. VXGE_HW_DEVICE_TIM_INT_MASK_SET(tim_int_mask0,
  1983. tim_int_mask1, vp->vpath->vp_id);
  1984. val64 = readq(&hldev->common_reg->tim_int_mask0);
  1985. if ((tim_int_mask0[VXGE_HW_VPATH_INTR_TX] != 0) ||
  1986. (tim_int_mask0[VXGE_HW_VPATH_INTR_RX] != 0)) {
  1987. writeq((~(tim_int_mask0[VXGE_HW_VPATH_INTR_TX] |
  1988. tim_int_mask0[VXGE_HW_VPATH_INTR_RX])) & val64,
  1989. &hldev->common_reg->tim_int_mask0);
  1990. }
  1991. if ((tim_int_mask1[VXGE_HW_VPATH_INTR_TX] != 0) ||
  1992. (tim_int_mask1[VXGE_HW_VPATH_INTR_RX] != 0)) {
  1993. __vxge_hw_pio_mem_write32_upper(
  1994. (~(tim_int_mask1[VXGE_HW_VPATH_INTR_TX] |
  1995. tim_int_mask1[VXGE_HW_VPATH_INTR_RX])) & val64,
  1996. &hldev->common_reg->tim_int_mask1);
  1997. }
  1998. }
  1999. /**
  2000. * vxge_hw_vpath_poll_rx - Poll Rx Virtual Path for completed
  2001. * descriptors and process the same.
  2002. * @ring: Handle to the ring object used for receive
  2003. *
  2004. * The function polls the Rx for the completed descriptors and calls
  2005. * the driver via supplied completion callback.
  2006. *
  2007. * Returns: VXGE_HW_OK, if the polling is completed successful.
  2008. * VXGE_HW_COMPLETIONS_REMAIN: There are still more completed
  2009. * descriptors available which are yet to be processed.
  2010. *
  2011. * See also: vxge_hw_vpath_poll_rx()
  2012. */
  2013. enum vxge_hw_status vxge_hw_vpath_poll_rx(struct __vxge_hw_ring *ring)
  2014. {
  2015. u8 t_code;
  2016. enum vxge_hw_status status = VXGE_HW_OK;
  2017. void *first_rxdh;
  2018. u64 val64 = 0;
  2019. int new_count = 0;
  2020. ring->cmpl_cnt = 0;
  2021. status = vxge_hw_ring_rxd_next_completed(ring, &first_rxdh, &t_code);
  2022. if (status == VXGE_HW_OK)
  2023. ring->callback(ring, first_rxdh,
  2024. t_code, ring->channel.userdata);
  2025. if (ring->cmpl_cnt != 0) {
  2026. ring->doorbell_cnt += ring->cmpl_cnt;
  2027. if (ring->doorbell_cnt >= ring->rxds_limit) {
  2028. /*
  2029. * Each RxD is of 4 qwords, update the number of
  2030. * qwords replenished
  2031. */
  2032. new_count = (ring->doorbell_cnt * 4);
  2033. /* For each block add 4 more qwords */
  2034. ring->total_db_cnt += ring->doorbell_cnt;
  2035. if (ring->total_db_cnt >= ring->rxds_per_block) {
  2036. new_count += 4;
  2037. /* Reset total count */
  2038. ring->total_db_cnt %= ring->rxds_per_block;
  2039. }
  2040. writeq(VXGE_HW_PRC_RXD_DOORBELL_NEW_QW_CNT(new_count),
  2041. &ring->vp_reg->prc_rxd_doorbell);
  2042. val64 =
  2043. readl(&ring->common_reg->titan_general_int_status);
  2044. ring->doorbell_cnt = 0;
  2045. }
  2046. }
  2047. return status;
  2048. }
  2049. /**
  2050. * vxge_hw_vpath_poll_tx - Poll Tx for completed descriptors and process
  2051. * the same.
  2052. * @fifo: Handle to the fifo object used for non offload send
  2053. *
  2054. * The function polls the Tx for the completed descriptors and calls
  2055. * the driver via supplied completion callback.
  2056. *
  2057. * Returns: VXGE_HW_OK, if the polling is completed successful.
  2058. * VXGE_HW_COMPLETIONS_REMAIN: There are still more completed
  2059. * descriptors available which are yet to be processed.
  2060. */
  2061. enum vxge_hw_status vxge_hw_vpath_poll_tx(struct __vxge_hw_fifo *fifo,
  2062. struct sk_buff ***skb_ptr, int nr_skb,
  2063. int *more)
  2064. {
  2065. enum vxge_hw_fifo_tcode t_code;
  2066. void *first_txdlh;
  2067. enum vxge_hw_status status = VXGE_HW_OK;
  2068. struct __vxge_hw_channel *channel;
  2069. channel = &fifo->channel;
  2070. status = vxge_hw_fifo_txdl_next_completed(fifo,
  2071. &first_txdlh, &t_code);
  2072. if (status == VXGE_HW_OK)
  2073. if (fifo->callback(fifo, first_txdlh, t_code,
  2074. channel->userdata, skb_ptr, nr_skb, more) != VXGE_HW_OK)
  2075. status = VXGE_HW_COMPLETIONS_REMAIN;
  2076. return status;
  2077. }