ioc4_serial.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2003-2005 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. /*
  9. * This file contains a module version of the ioc4 serial driver. This
  10. * includes all the support functions needed (support functions, etc.)
  11. * and the serial driver itself.
  12. */
  13. #include <linux/errno.h>
  14. #include <linux/tty.h>
  15. #include <linux/serial.h>
  16. #include <linux/serialP.h>
  17. #include <linux/circ_buf.h>
  18. #include <linux/serial_reg.h>
  19. #include <linux/module.h>
  20. #include <linux/pci.h>
  21. #include <linux/ioc4.h>
  22. #include <linux/serial_core.h>
  23. /*
  24. * interesting things about the ioc4
  25. */
  26. #define IOC4_NUM_SERIAL_PORTS 4 /* max ports per card */
  27. #define IOC4_NUM_CARDS 8 /* max cards per partition */
  28. #define GET_SIO_IR(_n) (_n == 0) ? (IOC4_SIO_IR_S0) : \
  29. (_n == 1) ? (IOC4_SIO_IR_S1) : \
  30. (_n == 2) ? (IOC4_SIO_IR_S2) : \
  31. (IOC4_SIO_IR_S3)
  32. #define GET_OTHER_IR(_n) (_n == 0) ? (IOC4_OTHER_IR_S0_MEMERR) : \
  33. (_n == 1) ? (IOC4_OTHER_IR_S1_MEMERR) : \
  34. (_n == 2) ? (IOC4_OTHER_IR_S2_MEMERR) : \
  35. (IOC4_OTHER_IR_S3_MEMERR)
  36. /*
  37. * All IOC4 registers are 32 bits wide.
  38. */
  39. /*
  40. * PCI Memory Space Map
  41. */
  42. #define IOC4_PCI_ERR_ADDR_L 0x000 /* Low Error Address */
  43. #define IOC4_PCI_ERR_ADDR_VLD (0x1 << 0)
  44. #define IOC4_PCI_ERR_ADDR_MST_ID_MSK (0xf << 1)
  45. #define IOC4_PCI_ERR_ADDR_MST_NUM_MSK (0xe << 1)
  46. #define IOC4_PCI_ERR_ADDR_MST_TYP_MSK (0x1 << 1)
  47. #define IOC4_PCI_ERR_ADDR_MUL_ERR (0x1 << 5)
  48. #define IOC4_PCI_ERR_ADDR_ADDR_MSK (0x3ffffff << 6)
  49. /* Interrupt types */
  50. #define IOC4_SIO_INTR_TYPE 0
  51. #define IOC4_OTHER_INTR_TYPE 1
  52. #define IOC4_NUM_INTR_TYPES 2
  53. /* Bitmasks for IOC4_SIO_IR, IOC4_SIO_IEC, and IOC4_SIO_IES */
  54. #define IOC4_SIO_IR_S0_TX_MT 0x00000001 /* Serial port 0 TX empty */
  55. #define IOC4_SIO_IR_S0_RX_FULL 0x00000002 /* Port 0 RX buf full */
  56. #define IOC4_SIO_IR_S0_RX_HIGH 0x00000004 /* Port 0 RX hiwat */
  57. #define IOC4_SIO_IR_S0_RX_TIMER 0x00000008 /* Port 0 RX timeout */
  58. #define IOC4_SIO_IR_S0_DELTA_DCD 0x00000010 /* Port 0 delta DCD */
  59. #define IOC4_SIO_IR_S0_DELTA_CTS 0x00000020 /* Port 0 delta CTS */
  60. #define IOC4_SIO_IR_S0_INT 0x00000040 /* Port 0 pass-thru intr */
  61. #define IOC4_SIO_IR_S0_TX_EXPLICIT 0x00000080 /* Port 0 explicit TX thru */
  62. #define IOC4_SIO_IR_S1_TX_MT 0x00000100 /* Serial port 1 */
  63. #define IOC4_SIO_IR_S1_RX_FULL 0x00000200 /* */
  64. #define IOC4_SIO_IR_S1_RX_HIGH 0x00000400 /* */
  65. #define IOC4_SIO_IR_S1_RX_TIMER 0x00000800 /* */
  66. #define IOC4_SIO_IR_S1_DELTA_DCD 0x00001000 /* */
  67. #define IOC4_SIO_IR_S1_DELTA_CTS 0x00002000 /* */
  68. #define IOC4_SIO_IR_S1_INT 0x00004000 /* */
  69. #define IOC4_SIO_IR_S1_TX_EXPLICIT 0x00008000 /* */
  70. #define IOC4_SIO_IR_S2_TX_MT 0x00010000 /* Serial port 2 */
  71. #define IOC4_SIO_IR_S2_RX_FULL 0x00020000 /* */
  72. #define IOC4_SIO_IR_S2_RX_HIGH 0x00040000 /* */
  73. #define IOC4_SIO_IR_S2_RX_TIMER 0x00080000 /* */
  74. #define IOC4_SIO_IR_S2_DELTA_DCD 0x00100000 /* */
  75. #define IOC4_SIO_IR_S2_DELTA_CTS 0x00200000 /* */
  76. #define IOC4_SIO_IR_S2_INT 0x00400000 /* */
  77. #define IOC4_SIO_IR_S2_TX_EXPLICIT 0x00800000 /* */
  78. #define IOC4_SIO_IR_S3_TX_MT 0x01000000 /* Serial port 3 */
  79. #define IOC4_SIO_IR_S3_RX_FULL 0x02000000 /* */
  80. #define IOC4_SIO_IR_S3_RX_HIGH 0x04000000 /* */
  81. #define IOC4_SIO_IR_S3_RX_TIMER 0x08000000 /* */
  82. #define IOC4_SIO_IR_S3_DELTA_DCD 0x10000000 /* */
  83. #define IOC4_SIO_IR_S3_DELTA_CTS 0x20000000 /* */
  84. #define IOC4_SIO_IR_S3_INT 0x40000000 /* */
  85. #define IOC4_SIO_IR_S3_TX_EXPLICIT 0x80000000 /* */
  86. /* Per device interrupt masks */
  87. #define IOC4_SIO_IR_S0 (IOC4_SIO_IR_S0_TX_MT | \
  88. IOC4_SIO_IR_S0_RX_FULL | \
  89. IOC4_SIO_IR_S0_RX_HIGH | \
  90. IOC4_SIO_IR_S0_RX_TIMER | \
  91. IOC4_SIO_IR_S0_DELTA_DCD | \
  92. IOC4_SIO_IR_S0_DELTA_CTS | \
  93. IOC4_SIO_IR_S0_INT | \
  94. IOC4_SIO_IR_S0_TX_EXPLICIT)
  95. #define IOC4_SIO_IR_S1 (IOC4_SIO_IR_S1_TX_MT | \
  96. IOC4_SIO_IR_S1_RX_FULL | \
  97. IOC4_SIO_IR_S1_RX_HIGH | \
  98. IOC4_SIO_IR_S1_RX_TIMER | \
  99. IOC4_SIO_IR_S1_DELTA_DCD | \
  100. IOC4_SIO_IR_S1_DELTA_CTS | \
  101. IOC4_SIO_IR_S1_INT | \
  102. IOC4_SIO_IR_S1_TX_EXPLICIT)
  103. #define IOC4_SIO_IR_S2 (IOC4_SIO_IR_S2_TX_MT | \
  104. IOC4_SIO_IR_S2_RX_FULL | \
  105. IOC4_SIO_IR_S2_RX_HIGH | \
  106. IOC4_SIO_IR_S2_RX_TIMER | \
  107. IOC4_SIO_IR_S2_DELTA_DCD | \
  108. IOC4_SIO_IR_S2_DELTA_CTS | \
  109. IOC4_SIO_IR_S2_INT | \
  110. IOC4_SIO_IR_S2_TX_EXPLICIT)
  111. #define IOC4_SIO_IR_S3 (IOC4_SIO_IR_S3_TX_MT | \
  112. IOC4_SIO_IR_S3_RX_FULL | \
  113. IOC4_SIO_IR_S3_RX_HIGH | \
  114. IOC4_SIO_IR_S3_RX_TIMER | \
  115. IOC4_SIO_IR_S3_DELTA_DCD | \
  116. IOC4_SIO_IR_S3_DELTA_CTS | \
  117. IOC4_SIO_IR_S3_INT | \
  118. IOC4_SIO_IR_S3_TX_EXPLICIT)
  119. /* Bitmasks for IOC4_OTHER_IR, IOC4_OTHER_IEC, and IOC4_OTHER_IES */
  120. #define IOC4_OTHER_IR_ATA_INT 0x00000001 /* ATAPI intr pass-thru */
  121. #define IOC4_OTHER_IR_ATA_MEMERR 0x00000002 /* ATAPI DMA PCI error */
  122. #define IOC4_OTHER_IR_S0_MEMERR 0x00000004 /* Port 0 PCI error */
  123. #define IOC4_OTHER_IR_S1_MEMERR 0x00000008 /* Port 1 PCI error */
  124. #define IOC4_OTHER_IR_S2_MEMERR 0x00000010 /* Port 2 PCI error */
  125. #define IOC4_OTHER_IR_S3_MEMERR 0x00000020 /* Port 3 PCI error */
  126. #define IOC4_OTHER_IR_KBD_INT 0x00000040 /* Keyboard/mouse */
  127. #define IOC4_OTHER_IR_RESERVED 0x007fff80 /* Reserved */
  128. #define IOC4_OTHER_IR_RT_INT 0x00800000 /* INT_OUT section output */
  129. #define IOC4_OTHER_IR_GEN_INT 0xff000000 /* Generic pins */
  130. #define IOC4_OTHER_IR_SER_MEMERR (IOC4_OTHER_IR_S0_MEMERR | IOC4_OTHER_IR_S1_MEMERR | \
  131. IOC4_OTHER_IR_S2_MEMERR | IOC4_OTHER_IR_S3_MEMERR)
  132. /* Bitmasks for IOC4_SIO_CR */
  133. #define IOC4_SIO_CR_CMD_PULSE_SHIFT 0 /* byte bus strobe shift */
  134. #define IOC4_SIO_CR_ARB_DIAG_TX0 0x00000000
  135. #define IOC4_SIO_CR_ARB_DIAG_RX0 0x00000010
  136. #define IOC4_SIO_CR_ARB_DIAG_TX1 0x00000020
  137. #define IOC4_SIO_CR_ARB_DIAG_RX1 0x00000030
  138. #define IOC4_SIO_CR_ARB_DIAG_TX2 0x00000040
  139. #define IOC4_SIO_CR_ARB_DIAG_RX2 0x00000050
  140. #define IOC4_SIO_CR_ARB_DIAG_TX3 0x00000060
  141. #define IOC4_SIO_CR_ARB_DIAG_RX3 0x00000070
  142. #define IOC4_SIO_CR_SIO_DIAG_IDLE 0x00000080 /* 0 -> active request among
  143. serial ports (ro) */
  144. /* Defs for some of the generic I/O pins */
  145. #define IOC4_GPCR_UART0_MODESEL 0x10 /* Pin is output to port 0
  146. mode sel */
  147. #define IOC4_GPCR_UART1_MODESEL 0x20 /* Pin is output to port 1
  148. mode sel */
  149. #define IOC4_GPCR_UART2_MODESEL 0x40 /* Pin is output to port 2
  150. mode sel */
  151. #define IOC4_GPCR_UART3_MODESEL 0x80 /* Pin is output to port 3
  152. mode sel */
  153. #define IOC4_GPPR_UART0_MODESEL_PIN 4 /* GIO pin controlling
  154. uart 0 mode select */
  155. #define IOC4_GPPR_UART1_MODESEL_PIN 5 /* GIO pin controlling
  156. uart 1 mode select */
  157. #define IOC4_GPPR_UART2_MODESEL_PIN 6 /* GIO pin controlling
  158. uart 2 mode select */
  159. #define IOC4_GPPR_UART3_MODESEL_PIN 7 /* GIO pin controlling
  160. uart 3 mode select */
  161. /* Bitmasks for serial RX status byte */
  162. #define IOC4_RXSB_OVERRUN 0x01 /* Char(s) lost */
  163. #define IOC4_RXSB_PAR_ERR 0x02 /* Parity error */
  164. #define IOC4_RXSB_FRAME_ERR 0x04 /* Framing error */
  165. #define IOC4_RXSB_BREAK 0x08 /* Break character */
  166. #define IOC4_RXSB_CTS 0x10 /* State of CTS */
  167. #define IOC4_RXSB_DCD 0x20 /* State of DCD */
  168. #define IOC4_RXSB_MODEM_VALID 0x40 /* DCD, CTS, and OVERRUN are valid */
  169. #define IOC4_RXSB_DATA_VALID 0x80 /* Data byte, FRAME_ERR PAR_ERR
  170. * & BREAK valid */
  171. /* Bitmasks for serial TX control byte */
  172. #define IOC4_TXCB_INT_WHEN_DONE 0x20 /* Interrupt after this byte is sent */
  173. #define IOC4_TXCB_INVALID 0x00 /* Byte is invalid */
  174. #define IOC4_TXCB_VALID 0x40 /* Byte is valid */
  175. #define IOC4_TXCB_MCR 0x80 /* Data<7:0> to modem control reg */
  176. #define IOC4_TXCB_DELAY 0xc0 /* Delay data<7:0> mSec */
  177. /* Bitmasks for IOC4_SBBR_L */
  178. #define IOC4_SBBR_L_SIZE 0x00000001 /* 0 == 1KB rings, 1 == 4KB rings */
  179. /* Bitmasks for IOC4_SSCR_<3:0> */
  180. #define IOC4_SSCR_RX_THRESHOLD 0x000001ff /* Hiwater mark */
  181. #define IOC4_SSCR_TX_TIMER_BUSY 0x00010000 /* TX timer in progress */
  182. #define IOC4_SSCR_HFC_EN 0x00020000 /* Hardware flow control enabled */
  183. #define IOC4_SSCR_RX_RING_DCD 0x00040000 /* Post RX record on delta-DCD */
  184. #define IOC4_SSCR_RX_RING_CTS 0x00080000 /* Post RX record on delta-CTS */
  185. #define IOC4_SSCR_DIAG 0x00200000 /* Bypass clock divider for sim */
  186. #define IOC4_SSCR_RX_DRAIN 0x08000000 /* Drain RX buffer to memory */
  187. #define IOC4_SSCR_DMA_EN 0x10000000 /* Enable ring buffer DMA */
  188. #define IOC4_SSCR_DMA_PAUSE 0x20000000 /* Pause DMA */
  189. #define IOC4_SSCR_PAUSE_STATE 0x40000000 /* Sets when PAUSE takes effect */
  190. #define IOC4_SSCR_RESET 0x80000000 /* Reset DMA channels */
  191. /* All producer/comsumer pointers are the same bitfield */
  192. #define IOC4_PROD_CONS_PTR_4K 0x00000ff8 /* For 4K buffers */
  193. #define IOC4_PROD_CONS_PTR_1K 0x000003f8 /* For 1K buffers */
  194. #define IOC4_PROD_CONS_PTR_OFF 3
  195. /* Bitmasks for IOC4_SRCIR_<3:0> */
  196. #define IOC4_SRCIR_ARM 0x80000000 /* Arm RX timer */
  197. /* Bitmasks for IOC4_SHADOW_<3:0> */
  198. #define IOC4_SHADOW_DR 0x00000001 /* Data ready */
  199. #define IOC4_SHADOW_OE 0x00000002 /* Overrun error */
  200. #define IOC4_SHADOW_PE 0x00000004 /* Parity error */
  201. #define IOC4_SHADOW_FE 0x00000008 /* Framing error */
  202. #define IOC4_SHADOW_BI 0x00000010 /* Break interrupt */
  203. #define IOC4_SHADOW_THRE 0x00000020 /* Xmit holding register empty */
  204. #define IOC4_SHADOW_TEMT 0x00000040 /* Xmit shift register empty */
  205. #define IOC4_SHADOW_RFCE 0x00000080 /* Char in RX fifo has an error */
  206. #define IOC4_SHADOW_DCTS 0x00010000 /* Delta clear to send */
  207. #define IOC4_SHADOW_DDCD 0x00080000 /* Delta data carrier detect */
  208. #define IOC4_SHADOW_CTS 0x00100000 /* Clear to send */
  209. #define IOC4_SHADOW_DCD 0x00800000 /* Data carrier detect */
  210. #define IOC4_SHADOW_DTR 0x01000000 /* Data terminal ready */
  211. #define IOC4_SHADOW_RTS 0x02000000 /* Request to send */
  212. #define IOC4_SHADOW_OUT1 0x04000000 /* 16550 OUT1 bit */
  213. #define IOC4_SHADOW_OUT2 0x08000000 /* 16550 OUT2 bit */
  214. #define IOC4_SHADOW_LOOP 0x10000000 /* Loopback enabled */
  215. /* Bitmasks for IOC4_SRTR_<3:0> */
  216. #define IOC4_SRTR_CNT 0x00000fff /* Reload value for RX timer */
  217. #define IOC4_SRTR_CNT_VAL 0x0fff0000 /* Current value of RX timer */
  218. #define IOC4_SRTR_CNT_VAL_SHIFT 16
  219. #define IOC4_SRTR_HZ 16000 /* SRTR clock frequency */
  220. /* Serial port register map used for DMA and PIO serial I/O */
  221. struct ioc4_serialregs {
  222. uint32_t sscr;
  223. uint32_t stpir;
  224. uint32_t stcir;
  225. uint32_t srpir;
  226. uint32_t srcir;
  227. uint32_t srtr;
  228. uint32_t shadow;
  229. };
  230. /* IOC4 UART register map */
  231. struct ioc4_uartregs {
  232. char i4u_lcr;
  233. union {
  234. char iir; /* read only */
  235. char fcr; /* write only */
  236. } u3;
  237. union {
  238. char ier; /* DLAB == 0 */
  239. char dlm; /* DLAB == 1 */
  240. } u2;
  241. union {
  242. char rbr; /* read only, DLAB == 0 */
  243. char thr; /* write only, DLAB == 0 */
  244. char dll; /* DLAB == 1 */
  245. } u1;
  246. char i4u_scr;
  247. char i4u_msr;
  248. char i4u_lsr;
  249. char i4u_mcr;
  250. };
  251. /* short names */
  252. #define i4u_dll u1.dll
  253. #define i4u_ier u2.ier
  254. #define i4u_dlm u2.dlm
  255. #define i4u_fcr u3.fcr
  256. /* Serial port registers used for DMA serial I/O */
  257. struct ioc4_serial {
  258. uint32_t sbbr01_l;
  259. uint32_t sbbr01_h;
  260. uint32_t sbbr23_l;
  261. uint32_t sbbr23_h;
  262. struct ioc4_serialregs port_0;
  263. struct ioc4_serialregs port_1;
  264. struct ioc4_serialregs port_2;
  265. struct ioc4_serialregs port_3;
  266. struct ioc4_uartregs uart_0;
  267. struct ioc4_uartregs uart_1;
  268. struct ioc4_uartregs uart_2;
  269. struct ioc4_uartregs uart_3;
  270. } ioc4_serial;
  271. /* UART clock speed */
  272. #define IOC4_SER_XIN_CLK_66 66666667
  273. #define IOC4_SER_XIN_CLK_33 33333333
  274. #define IOC4_W_IES 0
  275. #define IOC4_W_IEC 1
  276. typedef void ioc4_intr_func_f(void *, uint32_t);
  277. typedef ioc4_intr_func_f *ioc4_intr_func_t;
  278. static unsigned int Num_of_ioc4_cards;
  279. /* defining this will get you LOTS of great debug info */
  280. //#define DEBUG_INTERRUPTS
  281. #define DPRINT_CONFIG(_x...) ;
  282. //#define DPRINT_CONFIG(_x...) printk _x
  283. /* number of characters left in xmit buffer before we ask for more */
  284. #define WAKEUP_CHARS 256
  285. /* number of characters we want to transmit to the lower level at a time */
  286. #define IOC4_MAX_CHARS 256
  287. #define IOC4_FIFO_CHARS 255
  288. /* Device name we're using */
  289. #define DEVICE_NAME "ttyIOC"
  290. #define DEVICE_MAJOR 204
  291. #define DEVICE_MINOR 50
  292. /* register offsets */
  293. #define IOC4_SERIAL_OFFSET 0x300
  294. /* flags for next_char_state */
  295. #define NCS_BREAK 0x1
  296. #define NCS_PARITY 0x2
  297. #define NCS_FRAMING 0x4
  298. #define NCS_OVERRUN 0x8
  299. /* cause we need SOME parameters ... */
  300. #define MIN_BAUD_SUPPORTED 1200
  301. #define MAX_BAUD_SUPPORTED 115200
  302. /* protocol types supported */
  303. enum sio_proto {
  304. PROTO_RS232,
  305. PROTO_RS422
  306. };
  307. /* Notification types */
  308. #define N_DATA_READY 0x01
  309. #define N_OUTPUT_LOWAT 0x02
  310. #define N_BREAK 0x04
  311. #define N_PARITY_ERROR 0x08
  312. #define N_FRAMING_ERROR 0x10
  313. #define N_OVERRUN_ERROR 0x20
  314. #define N_DDCD 0x40
  315. #define N_DCTS 0x80
  316. #define N_ALL_INPUT (N_DATA_READY | N_BREAK | \
  317. N_PARITY_ERROR | N_FRAMING_ERROR | \
  318. N_OVERRUN_ERROR | N_DDCD | N_DCTS)
  319. #define N_ALL_OUTPUT N_OUTPUT_LOWAT
  320. #define N_ALL_ERRORS (N_PARITY_ERROR | N_FRAMING_ERROR | N_OVERRUN_ERROR)
  321. #define N_ALL (N_DATA_READY | N_OUTPUT_LOWAT | N_BREAK | \
  322. N_PARITY_ERROR | N_FRAMING_ERROR | \
  323. N_OVERRUN_ERROR | N_DDCD | N_DCTS)
  324. #define SER_DIVISOR(_x, clk) (((clk) + (_x) * 8) / ((_x) * 16))
  325. #define DIVISOR_TO_BAUD(div, clk) ((clk) / 16 / (div))
  326. /* Some masks */
  327. #define LCR_MASK_BITS_CHAR (UART_LCR_WLEN5 | UART_LCR_WLEN6 \
  328. | UART_LCR_WLEN7 | UART_LCR_WLEN8)
  329. #define LCR_MASK_STOP_BITS (UART_LCR_STOP)
  330. #define PENDING(_p) (readl(&(_p)->ip_mem->sio_ir.raw) & _p->ip_ienb)
  331. #define READ_SIO_IR(_p) readl(&(_p)->ip_mem->sio_ir.raw)
  332. /* Default to 4k buffers */
  333. #ifdef IOC4_1K_BUFFERS
  334. #define RING_BUF_SIZE 1024
  335. #define IOC4_BUF_SIZE_BIT 0
  336. #define PROD_CONS_MASK IOC4_PROD_CONS_PTR_1K
  337. #else
  338. #define RING_BUF_SIZE 4096
  339. #define IOC4_BUF_SIZE_BIT IOC4_SBBR_L_SIZE
  340. #define PROD_CONS_MASK IOC4_PROD_CONS_PTR_4K
  341. #endif
  342. #define TOTAL_RING_BUF_SIZE (RING_BUF_SIZE * 4)
  343. /*
  344. * This is the entry saved by the driver - one per card
  345. */
  346. struct ioc4_control {
  347. int ic_irq;
  348. struct {
  349. /* uart ports are allocated here */
  350. struct uart_port icp_uart_port;
  351. /* Handy reference material */
  352. struct ioc4_port *icp_port;
  353. } ic_port[IOC4_NUM_SERIAL_PORTS];
  354. struct ioc4_soft *ic_soft;
  355. };
  356. /*
  357. * per-IOC4 data structure
  358. */
  359. #define MAX_IOC4_INTR_ENTS (8 * sizeof(uint32_t))
  360. struct ioc4_soft {
  361. struct ioc4_misc_regs __iomem *is_ioc4_misc_addr;
  362. struct ioc4_serial __iomem *is_ioc4_serial_addr;
  363. /* Each interrupt type has an entry in the array */
  364. struct ioc4_intr_type {
  365. /*
  366. * Each in-use entry in this array contains at least
  367. * one nonzero bit in sd_bits; no two entries in this
  368. * array have overlapping sd_bits values.
  369. */
  370. struct ioc4_intr_info {
  371. uint32_t sd_bits;
  372. ioc4_intr_func_f *sd_intr;
  373. void *sd_info;
  374. } is_intr_info[MAX_IOC4_INTR_ENTS];
  375. /* Number of entries active in the above array */
  376. atomic_t is_num_intrs;
  377. } is_intr_type[IOC4_NUM_INTR_TYPES];
  378. /* is_ir_lock must be held while
  379. * modifying sio_ie values, so
  380. * we can be sure that sio_ie is
  381. * not changing when we read it
  382. * along with sio_ir.
  383. */
  384. spinlock_t is_ir_lock; /* SIO_IE[SC] mod lock */
  385. };
  386. /* Local port info for each IOC4 serial ports */
  387. struct ioc4_port {
  388. struct uart_port *ip_port;
  389. /* Back ptrs for this port */
  390. struct ioc4_control *ip_control;
  391. struct pci_dev *ip_pdev;
  392. struct ioc4_soft *ip_ioc4_soft;
  393. /* pci mem addresses */
  394. struct ioc4_misc_regs __iomem *ip_mem;
  395. struct ioc4_serial __iomem *ip_serial;
  396. struct ioc4_serialregs __iomem *ip_serial_regs;
  397. struct ioc4_uartregs __iomem *ip_uart_regs;
  398. /* Ring buffer page for this port */
  399. dma_addr_t ip_dma_ringbuf;
  400. /* vaddr of ring buffer */
  401. struct ring_buffer *ip_cpu_ringbuf;
  402. /* Rings for this port */
  403. struct ring *ip_inring;
  404. struct ring *ip_outring;
  405. /* Hook to port specific values */
  406. struct hooks *ip_hooks;
  407. spinlock_t ip_lock;
  408. /* Various rx/tx parameters */
  409. int ip_baud;
  410. int ip_tx_lowat;
  411. int ip_rx_timeout;
  412. /* Copy of notification bits */
  413. int ip_notify;
  414. /* Shadow copies of various registers so we don't need to PIO
  415. * read them constantly
  416. */
  417. uint32_t ip_ienb; /* Enabled interrupts */
  418. uint32_t ip_sscr;
  419. uint32_t ip_tx_prod;
  420. uint32_t ip_rx_cons;
  421. int ip_pci_bus_speed;
  422. unsigned char ip_flags;
  423. };
  424. /* tx low water mark. We need to notify the driver whenever tx is getting
  425. * close to empty so it can refill the tx buffer and keep things going.
  426. * Let's assume that if we interrupt 1 ms before the tx goes idle, we'll
  427. * have no trouble getting in more chars in time (I certainly hope so).
  428. */
  429. #define TX_LOWAT_LATENCY 1000
  430. #define TX_LOWAT_HZ (1000000 / TX_LOWAT_LATENCY)
  431. #define TX_LOWAT_CHARS(baud) (baud / 10 / TX_LOWAT_HZ)
  432. /* Flags per port */
  433. #define INPUT_HIGH 0x01
  434. #define DCD_ON 0x02
  435. #define LOWAT_WRITTEN 0x04
  436. #define READ_ABORTED 0x08
  437. /* Since each port has different register offsets and bitmasks
  438. * for everything, we'll store those that we need in tables so we
  439. * don't have to be constantly checking the port we are dealing with.
  440. */
  441. struct hooks {
  442. uint32_t intr_delta_dcd;
  443. uint32_t intr_delta_cts;
  444. uint32_t intr_tx_mt;
  445. uint32_t intr_rx_timer;
  446. uint32_t intr_rx_high;
  447. uint32_t intr_tx_explicit;
  448. uint32_t intr_dma_error;
  449. uint32_t intr_clear;
  450. uint32_t intr_all;
  451. int rs422_select_pin;
  452. };
  453. static struct hooks hooks_array[IOC4_NUM_SERIAL_PORTS] = {
  454. /* Values for port 0 */
  455. {
  456. IOC4_SIO_IR_S0_DELTA_DCD, IOC4_SIO_IR_S0_DELTA_CTS,
  457. IOC4_SIO_IR_S0_TX_MT, IOC4_SIO_IR_S0_RX_TIMER,
  458. IOC4_SIO_IR_S0_RX_HIGH, IOC4_SIO_IR_S0_TX_EXPLICIT,
  459. IOC4_OTHER_IR_S0_MEMERR,
  460. (IOC4_SIO_IR_S0_TX_MT | IOC4_SIO_IR_S0_RX_FULL |
  461. IOC4_SIO_IR_S0_RX_HIGH | IOC4_SIO_IR_S0_RX_TIMER |
  462. IOC4_SIO_IR_S0_DELTA_DCD | IOC4_SIO_IR_S0_DELTA_CTS |
  463. IOC4_SIO_IR_S0_INT | IOC4_SIO_IR_S0_TX_EXPLICIT),
  464. IOC4_SIO_IR_S0, IOC4_GPPR_UART0_MODESEL_PIN,
  465. },
  466. /* Values for port 1 */
  467. {
  468. IOC4_SIO_IR_S1_DELTA_DCD, IOC4_SIO_IR_S1_DELTA_CTS,
  469. IOC4_SIO_IR_S1_TX_MT, IOC4_SIO_IR_S1_RX_TIMER,
  470. IOC4_SIO_IR_S1_RX_HIGH, IOC4_SIO_IR_S1_TX_EXPLICIT,
  471. IOC4_OTHER_IR_S1_MEMERR,
  472. (IOC4_SIO_IR_S1_TX_MT | IOC4_SIO_IR_S1_RX_FULL |
  473. IOC4_SIO_IR_S1_RX_HIGH | IOC4_SIO_IR_S1_RX_TIMER |
  474. IOC4_SIO_IR_S1_DELTA_DCD | IOC4_SIO_IR_S1_DELTA_CTS |
  475. IOC4_SIO_IR_S1_INT | IOC4_SIO_IR_S1_TX_EXPLICIT),
  476. IOC4_SIO_IR_S1, IOC4_GPPR_UART1_MODESEL_PIN,
  477. },
  478. /* Values for port 2 */
  479. {
  480. IOC4_SIO_IR_S2_DELTA_DCD, IOC4_SIO_IR_S2_DELTA_CTS,
  481. IOC4_SIO_IR_S2_TX_MT, IOC4_SIO_IR_S2_RX_TIMER,
  482. IOC4_SIO_IR_S2_RX_HIGH, IOC4_SIO_IR_S2_TX_EXPLICIT,
  483. IOC4_OTHER_IR_S2_MEMERR,
  484. (IOC4_SIO_IR_S2_TX_MT | IOC4_SIO_IR_S2_RX_FULL |
  485. IOC4_SIO_IR_S2_RX_HIGH | IOC4_SIO_IR_S2_RX_TIMER |
  486. IOC4_SIO_IR_S2_DELTA_DCD | IOC4_SIO_IR_S2_DELTA_CTS |
  487. IOC4_SIO_IR_S2_INT | IOC4_SIO_IR_S2_TX_EXPLICIT),
  488. IOC4_SIO_IR_S2, IOC4_GPPR_UART2_MODESEL_PIN,
  489. },
  490. /* Values for port 3 */
  491. {
  492. IOC4_SIO_IR_S3_DELTA_DCD, IOC4_SIO_IR_S3_DELTA_CTS,
  493. IOC4_SIO_IR_S3_TX_MT, IOC4_SIO_IR_S3_RX_TIMER,
  494. IOC4_SIO_IR_S3_RX_HIGH, IOC4_SIO_IR_S3_TX_EXPLICIT,
  495. IOC4_OTHER_IR_S3_MEMERR,
  496. (IOC4_SIO_IR_S3_TX_MT | IOC4_SIO_IR_S3_RX_FULL |
  497. IOC4_SIO_IR_S3_RX_HIGH | IOC4_SIO_IR_S3_RX_TIMER |
  498. IOC4_SIO_IR_S3_DELTA_DCD | IOC4_SIO_IR_S3_DELTA_CTS |
  499. IOC4_SIO_IR_S3_INT | IOC4_SIO_IR_S3_TX_EXPLICIT),
  500. IOC4_SIO_IR_S3, IOC4_GPPR_UART3_MODESEL_PIN,
  501. }
  502. };
  503. /* A ring buffer entry */
  504. struct ring_entry {
  505. union {
  506. struct {
  507. uint32_t alldata;
  508. uint32_t allsc;
  509. } all;
  510. struct {
  511. char data[4]; /* data bytes */
  512. char sc[4]; /* status/control */
  513. } s;
  514. } u;
  515. };
  516. /* Test the valid bits in any of the 4 sc chars using "allsc" member */
  517. #define RING_ANY_VALID \
  518. ((uint32_t)(IOC4_RXSB_MODEM_VALID | IOC4_RXSB_DATA_VALID) * 0x01010101)
  519. #define ring_sc u.s.sc
  520. #define ring_data u.s.data
  521. #define ring_allsc u.all.allsc
  522. /* Number of entries per ring buffer. */
  523. #define ENTRIES_PER_RING (RING_BUF_SIZE / (int) sizeof(struct ring_entry))
  524. /* An individual ring */
  525. struct ring {
  526. struct ring_entry entries[ENTRIES_PER_RING];
  527. };
  528. /* The whole enchilada */
  529. struct ring_buffer {
  530. struct ring TX_0_OR_2;
  531. struct ring RX_0_OR_2;
  532. struct ring TX_1_OR_3;
  533. struct ring RX_1_OR_3;
  534. };
  535. /* Get a ring from a port struct */
  536. #define RING(_p, _wh) &(((struct ring_buffer *)((_p)->ip_cpu_ringbuf))->_wh)
  537. /* Infinite loop detection.
  538. */
  539. #define MAXITER 10000000
  540. /* Prototypes */
  541. static void receive_chars(struct uart_port *);
  542. static void handle_intr(void *arg, uint32_t sio_ir);
  543. /**
  544. * write_ireg - write the interrupt regs
  545. * @ioc4_soft: ptr to soft struct for this port
  546. * @val: value to write
  547. * @which: which register
  548. * @type: which ireg set
  549. */
  550. static inline void
  551. write_ireg(struct ioc4_soft *ioc4_soft, uint32_t val, int which, int type)
  552. {
  553. struct ioc4_misc_regs __iomem *mem = ioc4_soft->is_ioc4_misc_addr;
  554. unsigned long flags;
  555. spin_lock_irqsave(&ioc4_soft->is_ir_lock, flags);
  556. switch (type) {
  557. case IOC4_SIO_INTR_TYPE:
  558. switch (which) {
  559. case IOC4_W_IES:
  560. writel(val, &mem->sio_ies.raw);
  561. break;
  562. case IOC4_W_IEC:
  563. writel(val, &mem->sio_iec.raw);
  564. break;
  565. }
  566. break;
  567. case IOC4_OTHER_INTR_TYPE:
  568. switch (which) {
  569. case IOC4_W_IES:
  570. writel(val, &mem->other_ies.raw);
  571. break;
  572. case IOC4_W_IEC:
  573. writel(val, &mem->other_iec.raw);
  574. break;
  575. }
  576. break;
  577. default:
  578. break;
  579. }
  580. spin_unlock_irqrestore(&ioc4_soft->is_ir_lock, flags);
  581. }
  582. /**
  583. * set_baud - Baud rate setting code
  584. * @port: port to set
  585. * @baud: baud rate to use
  586. */
  587. static int set_baud(struct ioc4_port *port, int baud)
  588. {
  589. int actual_baud;
  590. int diff;
  591. int lcr;
  592. unsigned short divisor;
  593. struct ioc4_uartregs __iomem *uart;
  594. divisor = SER_DIVISOR(baud, port->ip_pci_bus_speed);
  595. if (!divisor)
  596. return 1;
  597. actual_baud = DIVISOR_TO_BAUD(divisor, port->ip_pci_bus_speed);
  598. diff = actual_baud - baud;
  599. if (diff < 0)
  600. diff = -diff;
  601. /* If we're within 1%, we've found a match */
  602. if (diff * 100 > actual_baud)
  603. return 1;
  604. uart = port->ip_uart_regs;
  605. lcr = readb(&uart->i4u_lcr);
  606. writeb(lcr | UART_LCR_DLAB, &uart->i4u_lcr);
  607. writeb((unsigned char)divisor, &uart->i4u_dll);
  608. writeb((unsigned char)(divisor >> 8), &uart->i4u_dlm);
  609. writeb(lcr, &uart->i4u_lcr);
  610. return 0;
  611. }
  612. /**
  613. * get_ioc4_port - given a uart port, return the control structure
  614. * @port: uart port
  615. */
  616. static struct ioc4_port *get_ioc4_port(struct uart_port *the_port)
  617. {
  618. struct ioc4_driver_data *idd = dev_get_drvdata(the_port->dev);
  619. struct ioc4_control *control = idd->idd_serial_data;
  620. int ii;
  621. if (control) {
  622. for ( ii = 0; ii < IOC4_NUM_SERIAL_PORTS; ii++ ) {
  623. if (!control->ic_port[ii].icp_port)
  624. continue;
  625. if (the_port == control->ic_port[ii].icp_port->ip_port)
  626. return control->ic_port[ii].icp_port;
  627. }
  628. }
  629. return NULL;
  630. }
  631. /* The IOC4 hardware provides no atomic way to determine if interrupts
  632. * are pending since two reads are required to do so. The handler must
  633. * read the SIO_IR and the SIO_IES, and take the logical and of the
  634. * two. When this value is zero, all interrupts have been serviced and
  635. * the handler may return.
  636. *
  637. * This has the unfortunate "hole" that, if some other CPU or
  638. * some other thread or some higher level interrupt manages to
  639. * modify SIO_IE between our reads of SIO_IR and SIO_IE, we may
  640. * think we have observed SIO_IR&SIO_IE==0 when in fact this
  641. * condition never really occurred.
  642. *
  643. * To solve this, we use a simple spinlock that must be held
  644. * whenever modifying SIO_IE; holding this lock while observing
  645. * both SIO_IR and SIO_IE guarantees that we do not falsely
  646. * conclude that no enabled interrupts are pending.
  647. */
  648. static inline uint32_t
  649. pending_intrs(struct ioc4_soft *soft, int type)
  650. {
  651. struct ioc4_misc_regs __iomem *mem = soft->is_ioc4_misc_addr;
  652. unsigned long flag;
  653. uint32_t intrs = 0;
  654. BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
  655. || (type == IOC4_OTHER_INTR_TYPE)));
  656. spin_lock_irqsave(&soft->is_ir_lock, flag);
  657. switch (type) {
  658. case IOC4_SIO_INTR_TYPE:
  659. intrs = readl(&mem->sio_ir.raw) & readl(&mem->sio_ies.raw);
  660. break;
  661. case IOC4_OTHER_INTR_TYPE:
  662. intrs = readl(&mem->other_ir.raw) & readl(&mem->other_ies.raw);
  663. /* Don't process any ATA interrupte */
  664. intrs &= ~(IOC4_OTHER_IR_ATA_INT | IOC4_OTHER_IR_ATA_MEMERR);
  665. break;
  666. default:
  667. break;
  668. }
  669. spin_unlock_irqrestore(&soft->is_ir_lock, flag);
  670. return intrs;
  671. }
  672. /**
  673. * port_init - Initialize the sio and ioc4 hardware for a given port
  674. * called per port from attach...
  675. * @port: port to initialize
  676. */
  677. static int inline port_init(struct ioc4_port *port)
  678. {
  679. uint32_t sio_cr;
  680. struct hooks *hooks = port->ip_hooks;
  681. struct ioc4_uartregs __iomem *uart;
  682. /* Idle the IOC4 serial interface */
  683. writel(IOC4_SSCR_RESET, &port->ip_serial_regs->sscr);
  684. /* Wait until any pending bus activity for this port has ceased */
  685. do
  686. sio_cr = readl(&port->ip_mem->sio_cr.raw);
  687. while (!(sio_cr & IOC4_SIO_CR_SIO_DIAG_IDLE));
  688. /* Finish reset sequence */
  689. writel(0, &port->ip_serial_regs->sscr);
  690. /* Once RESET is done, reload cached tx_prod and rx_cons values
  691. * and set rings to empty by making prod == cons
  692. */
  693. port->ip_tx_prod = readl(&port->ip_serial_regs->stcir) & PROD_CONS_MASK;
  694. writel(port->ip_tx_prod, &port->ip_serial_regs->stpir);
  695. port->ip_rx_cons = readl(&port->ip_serial_regs->srpir) & PROD_CONS_MASK;
  696. writel(port->ip_rx_cons | IOC4_SRCIR_ARM, &port->ip_serial_regs->srcir);
  697. /* Disable interrupts for this 16550 */
  698. uart = port->ip_uart_regs;
  699. writeb(0, &uart->i4u_lcr);
  700. writeb(0, &uart->i4u_ier);
  701. /* Set the default baud */
  702. set_baud(port, port->ip_baud);
  703. /* Set line control to 8 bits no parity */
  704. writeb(UART_LCR_WLEN8 | 0, &uart->i4u_lcr);
  705. /* UART_LCR_STOP == 1 stop */
  706. /* Enable the FIFOs */
  707. writeb(UART_FCR_ENABLE_FIFO, &uart->i4u_fcr);
  708. /* then reset 16550 FIFOs */
  709. writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
  710. &uart->i4u_fcr);
  711. /* Clear modem control register */
  712. writeb(0, &uart->i4u_mcr);
  713. /* Clear deltas in modem status register */
  714. readb(&uart->i4u_msr);
  715. /* Only do this once per port pair */
  716. if (port->ip_hooks == &hooks_array[0]
  717. || port->ip_hooks == &hooks_array[2]) {
  718. unsigned long ring_pci_addr;
  719. uint32_t __iomem *sbbr_l;
  720. uint32_t __iomem *sbbr_h;
  721. if (port->ip_hooks == &hooks_array[0]) {
  722. sbbr_l = &port->ip_serial->sbbr01_l;
  723. sbbr_h = &port->ip_serial->sbbr01_h;
  724. } else {
  725. sbbr_l = &port->ip_serial->sbbr23_l;
  726. sbbr_h = &port->ip_serial->sbbr23_h;
  727. }
  728. ring_pci_addr = (unsigned long __iomem)port->ip_dma_ringbuf;
  729. DPRINT_CONFIG(("%s: ring_pci_addr 0x%lx\n",
  730. __FUNCTION__, ring_pci_addr));
  731. writel((unsigned int)((uint64_t)ring_pci_addr >> 32), sbbr_h);
  732. writel((unsigned int)ring_pci_addr | IOC4_BUF_SIZE_BIT, sbbr_l);
  733. }
  734. /* Set the receive timeout value to 10 msec */
  735. writel(IOC4_SRTR_HZ / 100, &port->ip_serial_regs->srtr);
  736. /* Set rx threshold, enable DMA */
  737. /* Set high water mark at 3/4 of full ring */
  738. port->ip_sscr = (ENTRIES_PER_RING * 3 / 4);
  739. writel(port->ip_sscr, &port->ip_serial_regs->sscr);
  740. /* Disable and clear all serial related interrupt bits */
  741. write_ireg(port->ip_ioc4_soft, hooks->intr_clear,
  742. IOC4_W_IEC, IOC4_SIO_INTR_TYPE);
  743. port->ip_ienb &= ~hooks->intr_clear;
  744. writel(hooks->intr_clear, &port->ip_mem->sio_ir.raw);
  745. return 0;
  746. }
  747. /**
  748. * handle_dma_error_intr - service any pending DMA error interrupts for the
  749. * given port - 2nd level called via sd_intr
  750. * @arg: handler arg
  751. * @other_ir: ioc4regs
  752. */
  753. static void handle_dma_error_intr(void *arg, uint32_t other_ir)
  754. {
  755. struct ioc4_port *port = (struct ioc4_port *)arg;
  756. struct hooks *hooks = port->ip_hooks;
  757. unsigned int flags;
  758. spin_lock_irqsave(&port->ip_lock, flags);
  759. /* ACK the interrupt */
  760. writel(hooks->intr_dma_error, &port->ip_mem->other_ir.raw);
  761. if (readl(&port->ip_mem->pci_err_addr_l.raw) & IOC4_PCI_ERR_ADDR_VLD) {
  762. printk(KERN_ERR
  763. "PCI error address is 0x%lx, "
  764. "master is serial port %c %s\n",
  765. (((uint64_t)readl(&port->ip_mem->pci_err_addr_h)
  766. << 32)
  767. | readl(&port->ip_mem->pci_err_addr_l.raw))
  768. & IOC4_PCI_ERR_ADDR_ADDR_MSK, '1' +
  769. ((char)(readl(&port->ip_mem->pci_err_addr_l.raw) &
  770. IOC4_PCI_ERR_ADDR_MST_NUM_MSK) >> 1),
  771. (readl(&port->ip_mem->pci_err_addr_l.raw)
  772. & IOC4_PCI_ERR_ADDR_MST_TYP_MSK)
  773. ? "RX" : "TX");
  774. if (readl(&port->ip_mem->pci_err_addr_l.raw)
  775. & IOC4_PCI_ERR_ADDR_MUL_ERR) {
  776. printk(KERN_ERR
  777. "Multiple errors occurred\n");
  778. }
  779. }
  780. spin_unlock_irqrestore(&port->ip_lock, flags);
  781. /* Re-enable DMA error interrupts */
  782. write_ireg(port->ip_ioc4_soft, hooks->intr_dma_error, IOC4_W_IES,
  783. IOC4_OTHER_INTR_TYPE);
  784. }
  785. /**
  786. * intr_connect - interrupt connect function
  787. * @soft: soft struct for this card
  788. * @type: interrupt type
  789. * @intrbits: bit pattern to set
  790. * @intr: handler function
  791. * @info: handler arg
  792. */
  793. static void
  794. intr_connect(struct ioc4_soft *soft, int type,
  795. uint32_t intrbits, ioc4_intr_func_f * intr, void *info)
  796. {
  797. int i;
  798. struct ioc4_intr_info *intr_ptr;
  799. BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
  800. || (type == IOC4_OTHER_INTR_TYPE)));
  801. i = atomic_inc(&soft-> is_intr_type[type].is_num_intrs) - 1;
  802. BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
  803. /* Save off the lower level interrupt handler */
  804. intr_ptr = &soft->is_intr_type[type].is_intr_info[i];
  805. intr_ptr->sd_bits = intrbits;
  806. intr_ptr->sd_intr = intr;
  807. intr_ptr->sd_info = info;
  808. }
  809. /**
  810. * ioc4_intr - Top level IOC4 interrupt handler.
  811. * @irq: irq value
  812. * @arg: handler arg
  813. * @regs: registers
  814. */
  815. static irqreturn_t ioc4_intr(int irq, void *arg, struct pt_regs *regs)
  816. {
  817. struct ioc4_soft *soft;
  818. uint32_t this_ir, this_mir;
  819. int xx, num_intrs = 0;
  820. int intr_type;
  821. int handled = 0;
  822. struct ioc4_intr_info *ii;
  823. soft = arg;
  824. for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
  825. num_intrs = (int)atomic_read(
  826. &soft->is_intr_type[intr_type].is_num_intrs);
  827. this_mir = this_ir = pending_intrs(soft, intr_type);
  828. /* Farm out the interrupt to the various drivers depending on
  829. * which interrupt bits are set.
  830. */
  831. for (xx = 0; xx < num_intrs; xx++) {
  832. ii = &soft->is_intr_type[intr_type].is_intr_info[xx];
  833. if ((this_mir = this_ir & ii->sd_bits)) {
  834. /* Disable owned interrupts, call handler */
  835. handled++;
  836. write_ireg(soft, ii->sd_bits, IOC4_W_IEC,
  837. intr_type);
  838. ii->sd_intr(ii->sd_info, this_mir);
  839. this_ir &= ~this_mir;
  840. }
  841. }
  842. }
  843. #ifdef DEBUG_INTERRUPTS
  844. {
  845. struct ioc4_misc_regs __iomem *mem = soft->is_ioc4_misc_addr;
  846. spinlock_t *lp = &soft->is_ir_lock;
  847. unsigned long flag;
  848. spin_lock_irqsave(&soft->is_ir_lock, flag);
  849. printk ("%s : %d : mem 0x%p sio_ir 0x%x sio_ies 0x%x "
  850. "other_ir 0x%x other_ies 0x%x mask 0x%x\n",
  851. __FUNCTION__, __LINE__,
  852. (void *)mem, readl(&mem->sio_ir.raw),
  853. readl(&mem->sio_ies.raw),
  854. readl(&mem->other_ir.raw),
  855. readl(&mem->other_ies.raw),
  856. IOC4_OTHER_IR_ATA_INT | IOC4_OTHER_IR_ATA_MEMERR);
  857. spin_unlock_irqrestore(&soft->is_ir_lock, flag);
  858. }
  859. #endif
  860. return handled ? IRQ_HANDLED : IRQ_NONE;
  861. }
  862. /**
  863. * ioc4_attach_local - Device initialization.
  864. * Called at *_attach() time for each
  865. * IOC4 with serial ports in the system.
  866. * @idd: Master module data for this IOC4
  867. */
  868. static int inline ioc4_attach_local(struct ioc4_driver_data *idd)
  869. {
  870. struct ioc4_port *port;
  871. struct ioc4_port *ports[IOC4_NUM_SERIAL_PORTS];
  872. int port_number;
  873. uint16_t ioc4_revid_min = 62;
  874. uint16_t ioc4_revid;
  875. struct pci_dev *pdev = idd->idd_pdev;
  876. struct ioc4_control* control = idd->idd_serial_data;
  877. struct ioc4_soft *soft = control->ic_soft;
  878. void __iomem *ioc4_misc = idd->idd_misc_regs;
  879. void __iomem *ioc4_serial = soft->is_ioc4_serial_addr;
  880. /* IOC4 firmware must be at least rev 62 */
  881. pci_read_config_word(pdev, PCI_COMMAND_SPECIAL, &ioc4_revid);
  882. printk(KERN_INFO "IOC4 firmware revision %d\n", ioc4_revid);
  883. if (ioc4_revid < ioc4_revid_min) {
  884. printk(KERN_WARNING
  885. "IOC4 serial not supported on firmware rev %d, "
  886. "please upgrade to rev %d or higher\n",
  887. ioc4_revid, ioc4_revid_min);
  888. return -EPERM;
  889. }
  890. BUG_ON(ioc4_misc == NULL);
  891. BUG_ON(ioc4_serial == NULL);
  892. /* Create port structures for each port */
  893. for (port_number = 0; port_number < IOC4_NUM_SERIAL_PORTS;
  894. port_number++) {
  895. port = kmalloc(sizeof(struct ioc4_port), GFP_KERNEL);
  896. if (!port) {
  897. printk(KERN_WARNING
  898. "IOC4 serial memory not available for port\n");
  899. return -ENOMEM;
  900. }
  901. memset(port, 0, sizeof(struct ioc4_port));
  902. spin_lock_init(&port->ip_lock);
  903. /* we need to remember the previous ones, to point back to
  904. * them farther down - setting up the ring buffers.
  905. */
  906. ports[port_number] = port;
  907. /* Allocate buffers and jumpstart the hardware. */
  908. control->ic_port[port_number].icp_port = port;
  909. port->ip_ioc4_soft = soft;
  910. port->ip_pdev = pdev;
  911. port->ip_ienb = 0;
  912. /* Use baud rate calculations based on detected PCI
  913. * bus speed. Simply test whether the PCI clock is
  914. * running closer to 66MHz or 33MHz.
  915. */
  916. if (idd->count_period/IOC4_EXTINT_COUNT_DIVISOR < 20) {
  917. port->ip_pci_bus_speed = IOC4_SER_XIN_CLK_66;
  918. } else {
  919. port->ip_pci_bus_speed = IOC4_SER_XIN_CLK_33;
  920. }
  921. port->ip_baud = 9600;
  922. port->ip_control = control;
  923. port->ip_mem = ioc4_misc;
  924. port->ip_serial = ioc4_serial;
  925. /* point to the right hook */
  926. port->ip_hooks = &hooks_array[port_number];
  927. /* Get direct hooks to the serial regs and uart regs
  928. * for this port
  929. */
  930. switch (port_number) {
  931. case 0:
  932. port->ip_serial_regs = &(port->ip_serial->port_0);
  933. port->ip_uart_regs = &(port->ip_serial->uart_0);
  934. break;
  935. case 1:
  936. port->ip_serial_regs = &(port->ip_serial->port_1);
  937. port->ip_uart_regs = &(port->ip_serial->uart_1);
  938. break;
  939. case 2:
  940. port->ip_serial_regs = &(port->ip_serial->port_2);
  941. port->ip_uart_regs = &(port->ip_serial->uart_2);
  942. break;
  943. default:
  944. case 3:
  945. port->ip_serial_regs = &(port->ip_serial->port_3);
  946. port->ip_uart_regs = &(port->ip_serial->uart_3);
  947. break;
  948. }
  949. /* ring buffers are 1 to a pair of ports */
  950. if (port_number && (port_number & 1)) {
  951. /* odd use the evens buffer */
  952. port->ip_dma_ringbuf =
  953. ports[port_number - 1]->ip_dma_ringbuf;
  954. port->ip_cpu_ringbuf =
  955. ports[port_number - 1]->ip_cpu_ringbuf;
  956. port->ip_inring = RING(port, RX_1_OR_3);
  957. port->ip_outring = RING(port, TX_1_OR_3);
  958. } else {
  959. if (port->ip_dma_ringbuf == 0) {
  960. port->ip_cpu_ringbuf = pci_alloc_consistent
  961. (pdev, TOTAL_RING_BUF_SIZE,
  962. &port->ip_dma_ringbuf);
  963. }
  964. BUG_ON(!((((int64_t)port->ip_dma_ringbuf) &
  965. (TOTAL_RING_BUF_SIZE - 1)) == 0));
  966. DPRINT_CONFIG(("%s : ip_cpu_ringbuf 0x%p "
  967. "ip_dma_ringbuf 0x%p\n",
  968. __FUNCTION__,
  969. (void *)port->ip_cpu_ringbuf,
  970. (void *)port->ip_dma_ringbuf));
  971. port->ip_inring = RING(port, RX_0_OR_2);
  972. port->ip_outring = RING(port, TX_0_OR_2);
  973. }
  974. DPRINT_CONFIG(("%s : port %d [addr 0x%p] control 0x%p",
  975. __FUNCTION__,
  976. port_number, (void *)port, (void *)control));
  977. DPRINT_CONFIG((" ip_serial_regs 0x%p ip_uart_regs 0x%p\n",
  978. (void *)port->ip_serial_regs,
  979. (void *)port->ip_uart_regs));
  980. /* Initialize the hardware for IOC4 */
  981. port_init(port);
  982. DPRINT_CONFIG(("%s: port_number %d port 0x%p inring 0x%p "
  983. "outring 0x%p\n",
  984. __FUNCTION__,
  985. port_number, (void *)port,
  986. (void *)port->ip_inring,
  987. (void *)port->ip_outring));
  988. /* Attach interrupt handlers */
  989. intr_connect(soft, IOC4_SIO_INTR_TYPE,
  990. GET_SIO_IR(port_number),
  991. handle_intr, port);
  992. intr_connect(soft, IOC4_OTHER_INTR_TYPE,
  993. GET_OTHER_IR(port_number),
  994. handle_dma_error_intr, port);
  995. }
  996. return 0;
  997. }
  998. /**
  999. * enable_intrs - enable interrupts
  1000. * @port: port to enable
  1001. * @mask: mask to use
  1002. */
  1003. static void enable_intrs(struct ioc4_port *port, uint32_t mask)
  1004. {
  1005. struct hooks *hooks = port->ip_hooks;
  1006. if ((port->ip_ienb & mask) != mask) {
  1007. write_ireg(port->ip_ioc4_soft, mask, IOC4_W_IES,
  1008. IOC4_SIO_INTR_TYPE);
  1009. port->ip_ienb |= mask;
  1010. }
  1011. if (port->ip_ienb)
  1012. write_ireg(port->ip_ioc4_soft, hooks->intr_dma_error,
  1013. IOC4_W_IES, IOC4_OTHER_INTR_TYPE);
  1014. }
  1015. /**
  1016. * local_open - local open a port
  1017. * @port: port to open
  1018. */
  1019. static inline int local_open(struct ioc4_port *port)
  1020. {
  1021. int spiniter = 0;
  1022. port->ip_flags = 0;
  1023. /* Pause the DMA interface if necessary */
  1024. if (port->ip_sscr & IOC4_SSCR_DMA_EN) {
  1025. writel(port->ip_sscr | IOC4_SSCR_DMA_PAUSE,
  1026. &port->ip_serial_regs->sscr);
  1027. while((readl(&port->ip_serial_regs-> sscr)
  1028. & IOC4_SSCR_PAUSE_STATE) == 0) {
  1029. spiniter++;
  1030. if (spiniter > MAXITER) {
  1031. return -1;
  1032. }
  1033. }
  1034. }
  1035. /* Reset the input fifo. If the uart received chars while the port
  1036. * was closed and DMA is not enabled, the uart may have a bunch of
  1037. * chars hanging around in its rx fifo which will not be discarded
  1038. * by rclr in the upper layer. We must get rid of them here.
  1039. */
  1040. writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR,
  1041. &port->ip_uart_regs->i4u_fcr);
  1042. writeb(UART_LCR_WLEN8, &port->ip_uart_regs->i4u_lcr);
  1043. /* UART_LCR_STOP == 1 stop */
  1044. /* Re-enable DMA, set default threshold to intr whenever there is
  1045. * data available.
  1046. */
  1047. port->ip_sscr &= ~IOC4_SSCR_RX_THRESHOLD;
  1048. port->ip_sscr |= 1; /* default threshold */
  1049. /* Plug in the new sscr. This implicitly clears the DMA_PAUSE
  1050. * flag if it was set above
  1051. */
  1052. writel(port->ip_sscr, &port->ip_serial_regs->sscr);
  1053. port->ip_tx_lowat = 1;
  1054. return 0;
  1055. }
  1056. /**
  1057. * set_rx_timeout - Set rx timeout and threshold values.
  1058. * @port: port to use
  1059. * @timeout: timeout value in ticks
  1060. */
  1061. static inline int set_rx_timeout(struct ioc4_port *port, int timeout)
  1062. {
  1063. int threshold;
  1064. port->ip_rx_timeout = timeout;
  1065. /* Timeout is in ticks. Let's figure out how many chars we
  1066. * can receive at the current baud rate in that interval
  1067. * and set the rx threshold to that amount. There are 4 chars
  1068. * per ring entry, so we'll divide the number of chars that will
  1069. * arrive in timeout by 4.
  1070. * So .... timeout * baud / 10 / HZ / 4, with HZ = 100.
  1071. */
  1072. threshold = timeout * port->ip_baud / 4000;
  1073. if (threshold == 0)
  1074. threshold = 1; /* otherwise we'll intr all the time! */
  1075. if ((unsigned)threshold > (unsigned)IOC4_SSCR_RX_THRESHOLD)
  1076. return 1;
  1077. port->ip_sscr &= ~IOC4_SSCR_RX_THRESHOLD;
  1078. port->ip_sscr |= threshold;
  1079. writel(port->ip_sscr, &port->ip_serial_regs->sscr);
  1080. /* Now set the rx timeout to the given value
  1081. * again timeout * IOC4_SRTR_HZ / HZ
  1082. */
  1083. timeout = timeout * IOC4_SRTR_HZ / 100;
  1084. if (timeout > IOC4_SRTR_CNT)
  1085. timeout = IOC4_SRTR_CNT;
  1086. writel(timeout, &port->ip_serial_regs->srtr);
  1087. return 0;
  1088. }
  1089. /**
  1090. * config_port - config the hardware
  1091. * @port: port to config
  1092. * @baud: baud rate for the port
  1093. * @byte_size: data size
  1094. * @stop_bits: number of stop bits
  1095. * @parenb: parity enable ?
  1096. * @parodd: odd parity ?
  1097. */
  1098. static inline int
  1099. config_port(struct ioc4_port *port,
  1100. int baud, int byte_size, int stop_bits, int parenb, int parodd)
  1101. {
  1102. char lcr, sizebits;
  1103. int spiniter = 0;
  1104. DPRINT_CONFIG(("%s: baud %d byte_size %d stop %d parenb %d parodd %d\n",
  1105. __FUNCTION__, baud, byte_size, stop_bits, parenb, parodd));
  1106. if (set_baud(port, baud))
  1107. return 1;
  1108. switch (byte_size) {
  1109. case 5:
  1110. sizebits = UART_LCR_WLEN5;
  1111. break;
  1112. case 6:
  1113. sizebits = UART_LCR_WLEN6;
  1114. break;
  1115. case 7:
  1116. sizebits = UART_LCR_WLEN7;
  1117. break;
  1118. case 8:
  1119. sizebits = UART_LCR_WLEN8;
  1120. break;
  1121. default:
  1122. return 1;
  1123. }
  1124. /* Pause the DMA interface if necessary */
  1125. if (port->ip_sscr & IOC4_SSCR_DMA_EN) {
  1126. writel(port->ip_sscr | IOC4_SSCR_DMA_PAUSE,
  1127. &port->ip_serial_regs->sscr);
  1128. while((readl(&port->ip_serial_regs->sscr)
  1129. & IOC4_SSCR_PAUSE_STATE) == 0) {
  1130. spiniter++;
  1131. if (spiniter > MAXITER)
  1132. return -1;
  1133. }
  1134. }
  1135. /* Clear relevant fields in lcr */
  1136. lcr = readb(&port->ip_uart_regs->i4u_lcr);
  1137. lcr &= ~(LCR_MASK_BITS_CHAR | UART_LCR_EPAR |
  1138. UART_LCR_PARITY | LCR_MASK_STOP_BITS);
  1139. /* Set byte size in lcr */
  1140. lcr |= sizebits;
  1141. /* Set parity */
  1142. if (parenb) {
  1143. lcr |= UART_LCR_PARITY;
  1144. if (!parodd)
  1145. lcr |= UART_LCR_EPAR;
  1146. }
  1147. /* Set stop bits */
  1148. if (stop_bits)
  1149. lcr |= UART_LCR_STOP /* 2 stop bits */ ;
  1150. writeb(lcr, &port->ip_uart_regs->i4u_lcr);
  1151. /* Re-enable the DMA interface if necessary */
  1152. if (port->ip_sscr & IOC4_SSCR_DMA_EN) {
  1153. writel(port->ip_sscr, &port->ip_serial_regs->sscr);
  1154. }
  1155. port->ip_baud = baud;
  1156. /* When we get within this number of ring entries of filling the
  1157. * entire ring on tx, place an EXPLICIT intr to generate a lowat
  1158. * notification when output has drained.
  1159. */
  1160. port->ip_tx_lowat = (TX_LOWAT_CHARS(baud) + 3) / 4;
  1161. if (port->ip_tx_lowat == 0)
  1162. port->ip_tx_lowat = 1;
  1163. set_rx_timeout(port, 2);
  1164. return 0;
  1165. }
  1166. /**
  1167. * do_write - Write bytes to the port. Returns the number of bytes
  1168. * actually written. Called from transmit_chars
  1169. * @port: port to use
  1170. * @buf: the stuff to write
  1171. * @len: how many bytes in 'buf'
  1172. */
  1173. static inline int do_write(struct ioc4_port *port, char *buf, int len)
  1174. {
  1175. int prod_ptr, cons_ptr, total = 0;
  1176. struct ring *outring;
  1177. struct ring_entry *entry;
  1178. struct hooks *hooks = port->ip_hooks;
  1179. BUG_ON(!(len >= 0));
  1180. prod_ptr = port->ip_tx_prod;
  1181. cons_ptr = readl(&port->ip_serial_regs->stcir) & PROD_CONS_MASK;
  1182. outring = port->ip_outring;
  1183. /* Maintain a 1-entry red-zone. The ring buffer is full when
  1184. * (cons - prod) % ring_size is 1. Rather than do this subtraction
  1185. * in the body of the loop, I'll do it now.
  1186. */
  1187. cons_ptr = (cons_ptr - (int)sizeof(struct ring_entry)) & PROD_CONS_MASK;
  1188. /* Stuff the bytes into the output */
  1189. while ((prod_ptr != cons_ptr) && (len > 0)) {
  1190. int xx;
  1191. /* Get 4 bytes (one ring entry) at a time */
  1192. entry = (struct ring_entry *)((caddr_t) outring + prod_ptr);
  1193. /* Invalidate all entries */
  1194. entry->ring_allsc = 0;
  1195. /* Copy in some bytes */
  1196. for (xx = 0; (xx < 4) && (len > 0); xx++) {
  1197. entry->ring_data[xx] = *buf++;
  1198. entry->ring_sc[xx] = IOC4_TXCB_VALID;
  1199. len--;
  1200. total++;
  1201. }
  1202. /* If we are within some small threshold of filling up the
  1203. * entire ring buffer, we must place an EXPLICIT intr here
  1204. * to generate a lowat interrupt in case we subsequently
  1205. * really do fill up the ring and the caller goes to sleep.
  1206. * No need to place more than one though.
  1207. */
  1208. if (!(port->ip_flags & LOWAT_WRITTEN) &&
  1209. ((cons_ptr - prod_ptr) & PROD_CONS_MASK)
  1210. <= port->ip_tx_lowat
  1211. * (int)sizeof(struct ring_entry)) {
  1212. port->ip_flags |= LOWAT_WRITTEN;
  1213. entry->ring_sc[0] |= IOC4_TXCB_INT_WHEN_DONE;
  1214. }
  1215. /* Go on to next entry */
  1216. prod_ptr += sizeof(struct ring_entry);
  1217. prod_ptr &= PROD_CONS_MASK;
  1218. }
  1219. /* If we sent something, start DMA if necessary */
  1220. if (total > 0 && !(port->ip_sscr & IOC4_SSCR_DMA_EN)) {
  1221. port->ip_sscr |= IOC4_SSCR_DMA_EN;
  1222. writel(port->ip_sscr, &port->ip_serial_regs->sscr);
  1223. }
  1224. /* Store the new producer pointer. If tx is disabled, we stuff the
  1225. * data into the ring buffer, but we don't actually start tx.
  1226. */
  1227. if (!uart_tx_stopped(port->ip_port)) {
  1228. writel(prod_ptr, &port->ip_serial_regs->stpir);
  1229. /* If we are now transmitting, enable tx_mt interrupt so we
  1230. * can disable DMA if necessary when the tx finishes.
  1231. */
  1232. if (total > 0)
  1233. enable_intrs(port, hooks->intr_tx_mt);
  1234. }
  1235. port->ip_tx_prod = prod_ptr;
  1236. return total;
  1237. }
  1238. /**
  1239. * disable_intrs - disable interrupts
  1240. * @port: port to enable
  1241. * @mask: mask to use
  1242. */
  1243. static void disable_intrs(struct ioc4_port *port, uint32_t mask)
  1244. {
  1245. struct hooks *hooks = port->ip_hooks;
  1246. if (port->ip_ienb & mask) {
  1247. write_ireg(port->ip_ioc4_soft, mask, IOC4_W_IEC,
  1248. IOC4_SIO_INTR_TYPE);
  1249. port->ip_ienb &= ~mask;
  1250. }
  1251. if (!port->ip_ienb)
  1252. write_ireg(port->ip_ioc4_soft, hooks->intr_dma_error,
  1253. IOC4_W_IEC, IOC4_OTHER_INTR_TYPE);
  1254. }
  1255. /**
  1256. * set_notification - Modify event notification
  1257. * @port: port to use
  1258. * @mask: events mask
  1259. * @set_on: set ?
  1260. */
  1261. static int set_notification(struct ioc4_port *port, int mask, int set_on)
  1262. {
  1263. struct hooks *hooks = port->ip_hooks;
  1264. uint32_t intrbits, sscrbits;
  1265. BUG_ON(!mask);
  1266. intrbits = sscrbits = 0;
  1267. if (mask & N_DATA_READY)
  1268. intrbits |= (hooks->intr_rx_timer | hooks->intr_rx_high);
  1269. if (mask & N_OUTPUT_LOWAT)
  1270. intrbits |= hooks->intr_tx_explicit;
  1271. if (mask & N_DDCD) {
  1272. intrbits |= hooks->intr_delta_dcd;
  1273. sscrbits |= IOC4_SSCR_RX_RING_DCD;
  1274. }
  1275. if (mask & N_DCTS)
  1276. intrbits |= hooks->intr_delta_cts;
  1277. if (set_on) {
  1278. enable_intrs(port, intrbits);
  1279. port->ip_notify |= mask;
  1280. port->ip_sscr |= sscrbits;
  1281. } else {
  1282. disable_intrs(port, intrbits);
  1283. port->ip_notify &= ~mask;
  1284. port->ip_sscr &= ~sscrbits;
  1285. }
  1286. /* We require DMA if either DATA_READY or DDCD notification is
  1287. * currently requested. If neither of these is requested and
  1288. * there is currently no tx in progress, DMA may be disabled.
  1289. */
  1290. if (port->ip_notify & (N_DATA_READY | N_DDCD))
  1291. port->ip_sscr |= IOC4_SSCR_DMA_EN;
  1292. else if (!(port->ip_ienb & hooks->intr_tx_mt))
  1293. port->ip_sscr &= ~IOC4_SSCR_DMA_EN;
  1294. writel(port->ip_sscr, &port->ip_serial_regs->sscr);
  1295. return 0;
  1296. }
  1297. /**
  1298. * set_mcr - set the master control reg
  1299. * @the_port: port to use
  1300. * @set: set ?
  1301. * @mask1: mcr mask
  1302. * @mask2: shadow mask
  1303. */
  1304. static inline int set_mcr(struct uart_port *the_port, int set,
  1305. int mask1, int mask2)
  1306. {
  1307. struct ioc4_port *port = get_ioc4_port(the_port);
  1308. uint32_t shadow;
  1309. int spiniter = 0;
  1310. char mcr;
  1311. if (!port)
  1312. return -1;
  1313. /* Pause the DMA interface if necessary */
  1314. if (port->ip_sscr & IOC4_SSCR_DMA_EN) {
  1315. writel(port->ip_sscr | IOC4_SSCR_DMA_PAUSE,
  1316. &port->ip_serial_regs->sscr);
  1317. while ((readl(&port->ip_serial_regs->sscr)
  1318. & IOC4_SSCR_PAUSE_STATE) == 0) {
  1319. spiniter++;
  1320. if (spiniter > MAXITER)
  1321. return -1;
  1322. }
  1323. }
  1324. shadow = readl(&port->ip_serial_regs->shadow);
  1325. mcr = (shadow & 0xff000000) >> 24;
  1326. /* Set new value */
  1327. if (set) {
  1328. mcr |= mask1;
  1329. shadow |= mask2;
  1330. } else {
  1331. mcr &= ~mask1;
  1332. shadow &= ~mask2;
  1333. }
  1334. writeb(mcr, &port->ip_uart_regs->i4u_mcr);
  1335. writel(shadow, &port->ip_serial_regs->shadow);
  1336. /* Re-enable the DMA interface if necessary */
  1337. if (port->ip_sscr & IOC4_SSCR_DMA_EN) {
  1338. writel(port->ip_sscr, &port->ip_serial_regs->sscr);
  1339. }
  1340. return 0;
  1341. }
  1342. /**
  1343. * ioc4_set_proto - set the protocol for the port
  1344. * @port: port to use
  1345. * @proto: protocol to use
  1346. */
  1347. static int ioc4_set_proto(struct ioc4_port *port, enum sio_proto proto)
  1348. {
  1349. struct hooks *hooks = port->ip_hooks;
  1350. switch (proto) {
  1351. case PROTO_RS232:
  1352. /* Clear the appropriate GIO pin */
  1353. writel(0, (&port->ip_mem->gppr[hooks->rs422_select_pin].raw));
  1354. break;
  1355. case PROTO_RS422:
  1356. /* Set the appropriate GIO pin */
  1357. writel(1, (&port->ip_mem->gppr[hooks->rs422_select_pin].raw));
  1358. break;
  1359. default:
  1360. return 1;
  1361. }
  1362. return 0;
  1363. }
  1364. /**
  1365. * transmit_chars - upper level write, called with ip_lock
  1366. * @the_port: port to write
  1367. */
  1368. static void transmit_chars(struct uart_port *the_port)
  1369. {
  1370. int xmit_count, tail, head;
  1371. int result;
  1372. char *start;
  1373. struct tty_struct *tty;
  1374. struct ioc4_port *port = get_ioc4_port(the_port);
  1375. struct uart_info *info;
  1376. if (!the_port)
  1377. return;
  1378. if (!port)
  1379. return;
  1380. info = the_port->info;
  1381. tty = info->tty;
  1382. if (uart_circ_empty(&info->xmit) || uart_tx_stopped(the_port)) {
  1383. /* Nothing to do or hw stopped */
  1384. set_notification(port, N_ALL_OUTPUT, 0);
  1385. return;
  1386. }
  1387. head = info->xmit.head;
  1388. tail = info->xmit.tail;
  1389. start = (char *)&info->xmit.buf[tail];
  1390. /* write out all the data or until the end of the buffer */
  1391. xmit_count = (head < tail) ? (UART_XMIT_SIZE - tail) : (head - tail);
  1392. if (xmit_count > 0) {
  1393. result = do_write(port, start, xmit_count);
  1394. if (result > 0) {
  1395. /* booking */
  1396. xmit_count -= result;
  1397. the_port->icount.tx += result;
  1398. /* advance the pointers */
  1399. tail += result;
  1400. tail &= UART_XMIT_SIZE - 1;
  1401. info->xmit.tail = tail;
  1402. start = (char *)&info->xmit.buf[tail];
  1403. }
  1404. }
  1405. if (uart_circ_chars_pending(&info->xmit) < WAKEUP_CHARS)
  1406. uart_write_wakeup(the_port);
  1407. if (uart_circ_empty(&info->xmit)) {
  1408. set_notification(port, N_OUTPUT_LOWAT, 0);
  1409. } else {
  1410. set_notification(port, N_OUTPUT_LOWAT, 1);
  1411. }
  1412. }
  1413. /**
  1414. * ioc4_change_speed - change the speed of the port
  1415. * @the_port: port to change
  1416. * @new_termios: new termios settings
  1417. * @old_termios: old termios settings
  1418. */
  1419. static void
  1420. ioc4_change_speed(struct uart_port *the_port,
  1421. struct termios *new_termios, struct termios *old_termios)
  1422. {
  1423. struct ioc4_port *port = get_ioc4_port(the_port);
  1424. int baud, bits;
  1425. unsigned cflag;
  1426. int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8;
  1427. struct uart_info *info = the_port->info;
  1428. cflag = new_termios->c_cflag;
  1429. switch (cflag & CSIZE) {
  1430. case CS5:
  1431. new_data = 5;
  1432. bits = 7;
  1433. break;
  1434. case CS6:
  1435. new_data = 6;
  1436. bits = 8;
  1437. break;
  1438. case CS7:
  1439. new_data = 7;
  1440. bits = 9;
  1441. break;
  1442. case CS8:
  1443. new_data = 8;
  1444. bits = 10;
  1445. break;
  1446. default:
  1447. /* cuz we always need a default ... */
  1448. new_data = 5;
  1449. bits = 7;
  1450. break;
  1451. }
  1452. if (cflag & CSTOPB) {
  1453. bits++;
  1454. new_stop = 1;
  1455. }
  1456. if (cflag & PARENB) {
  1457. bits++;
  1458. new_parity_enable = 1;
  1459. if (cflag & PARODD)
  1460. new_parity = 1;
  1461. }
  1462. baud = uart_get_baud_rate(the_port, new_termios, old_termios,
  1463. MIN_BAUD_SUPPORTED, MAX_BAUD_SUPPORTED);
  1464. DPRINT_CONFIG(("%s: returned baud %d\n", __FUNCTION__, baud));
  1465. /* default is 9600 */
  1466. if (!baud)
  1467. baud = 9600;
  1468. if (!the_port->fifosize)
  1469. the_port->fifosize = IOC4_FIFO_CHARS;
  1470. the_port->timeout = ((the_port->fifosize * HZ * bits) / (baud / 10));
  1471. the_port->timeout += HZ / 50; /* Add .02 seconds of slop */
  1472. the_port->ignore_status_mask = N_ALL_INPUT;
  1473. info->tty->low_latency = 1;
  1474. if (I_IGNPAR(info->tty))
  1475. the_port->ignore_status_mask &= ~(N_PARITY_ERROR
  1476. | N_FRAMING_ERROR);
  1477. if (I_IGNBRK(info->tty)) {
  1478. the_port->ignore_status_mask &= ~N_BREAK;
  1479. if (I_IGNPAR(info->tty))
  1480. the_port->ignore_status_mask &= ~N_OVERRUN_ERROR;
  1481. }
  1482. if (!(cflag & CREAD)) {
  1483. /* ignore everything */
  1484. the_port->ignore_status_mask &= ~N_DATA_READY;
  1485. }
  1486. if (cflag & CRTSCTS) {
  1487. port->ip_sscr |= IOC4_SSCR_HFC_EN;
  1488. }
  1489. else {
  1490. port->ip_sscr &= ~IOC4_SSCR_HFC_EN;
  1491. }
  1492. writel(port->ip_sscr, &port->ip_serial_regs->sscr);
  1493. /* Set the configuration and proper notification call */
  1494. DPRINT_CONFIG(("%s : port 0x%p cflag 0%o "
  1495. "config_port(baud %d data %d stop %d p enable %d parity %d),"
  1496. " notification 0x%x\n",
  1497. __FUNCTION__, (void *)port, cflag, baud, new_data, new_stop,
  1498. new_parity_enable, new_parity, the_port->ignore_status_mask));
  1499. if ((config_port(port, baud, /* baud */
  1500. new_data, /* byte size */
  1501. new_stop, /* stop bits */
  1502. new_parity_enable, /* set parity */
  1503. new_parity)) >= 0) { /* parity 1==odd */
  1504. set_notification(port, the_port->ignore_status_mask, 1);
  1505. }
  1506. }
  1507. /**
  1508. * ic4_startup_local - Start up the serial port - returns >= 0 if no errors
  1509. * @the_port: Port to operate on
  1510. */
  1511. static inline int ic4_startup_local(struct uart_port *the_port)
  1512. {
  1513. struct ioc4_port *port;
  1514. struct uart_info *info;
  1515. if (!the_port)
  1516. return -1;
  1517. port = get_ioc4_port(the_port);
  1518. if (!port)
  1519. return -1;
  1520. info = the_port->info;
  1521. local_open(port);
  1522. /* set the speed of the serial port */
  1523. ioc4_change_speed(the_port, info->tty->termios, (struct termios *)0);
  1524. return 0;
  1525. }
  1526. /*
  1527. * ioc4_cb_output_lowat - called when the output low water mark is hit
  1528. * @port: port to output
  1529. */
  1530. static void ioc4_cb_output_lowat(struct ioc4_port *port)
  1531. {
  1532. unsigned long pflags;
  1533. /* ip_lock is set on the call here */
  1534. if (port->ip_port) {
  1535. spin_lock_irqsave(&port->ip_port->lock, pflags);
  1536. transmit_chars(port->ip_port);
  1537. spin_unlock_irqrestore(&port->ip_port->lock, pflags);
  1538. }
  1539. }
  1540. /**
  1541. * handle_intr - service any interrupts for the given port - 2nd level
  1542. * called via sd_intr
  1543. * @arg: handler arg
  1544. * @sio_ir: ioc4regs
  1545. */
  1546. static void handle_intr(void *arg, uint32_t sio_ir)
  1547. {
  1548. struct ioc4_port *port = (struct ioc4_port *)arg;
  1549. struct hooks *hooks = port->ip_hooks;
  1550. unsigned int rx_high_rd_aborted = 0;
  1551. unsigned int flags;
  1552. struct uart_port *the_port;
  1553. int loop_counter;
  1554. /* Possible race condition here: The tx_mt interrupt bit may be
  1555. * cleared without the intervention of the interrupt handler,
  1556. * e.g. by a write. If the top level interrupt handler reads a
  1557. * tx_mt, then some other processor does a write, starting up
  1558. * output, then we come in here, see the tx_mt and stop DMA, the
  1559. * output started by the other processor will hang. Thus we can
  1560. * only rely on tx_mt being legitimate if it is read while the
  1561. * port lock is held. Therefore this bit must be ignored in the
  1562. * passed in interrupt mask which was read by the top level
  1563. * interrupt handler since the port lock was not held at the time
  1564. * it was read. We can only rely on this bit being accurate if it
  1565. * is read while the port lock is held. So we'll clear it for now,
  1566. * and reload it later once we have the port lock.
  1567. */
  1568. sio_ir &= ~(hooks->intr_tx_mt);
  1569. spin_lock_irqsave(&port->ip_lock, flags);
  1570. loop_counter = MAXITER; /* to avoid hangs */
  1571. do {
  1572. uint32_t shadow;
  1573. if ( loop_counter-- <= 0 ) {
  1574. printk(KERN_WARNING "IOC4 serial: "
  1575. "possible hang condition/"
  1576. "port stuck on interrupt.\n");
  1577. break;
  1578. }
  1579. /* Handle a DCD change */
  1580. if (sio_ir & hooks->intr_delta_dcd) {
  1581. /* ACK the interrupt */
  1582. writel(hooks->intr_delta_dcd,
  1583. &port->ip_mem->sio_ir.raw);
  1584. shadow = readl(&port->ip_serial_regs->shadow);
  1585. if ((port->ip_notify & N_DDCD)
  1586. && (shadow & IOC4_SHADOW_DCD)
  1587. && (port->ip_port)) {
  1588. the_port = port->ip_port;
  1589. the_port->icount.dcd = 1;
  1590. wake_up_interruptible
  1591. (&the_port-> info->delta_msr_wait);
  1592. } else if ((port->ip_notify & N_DDCD)
  1593. && !(shadow & IOC4_SHADOW_DCD)) {
  1594. /* Flag delta DCD/no DCD */
  1595. port->ip_flags |= DCD_ON;
  1596. }
  1597. }
  1598. /* Handle a CTS change */
  1599. if (sio_ir & hooks->intr_delta_cts) {
  1600. /* ACK the interrupt */
  1601. writel(hooks->intr_delta_cts,
  1602. &port->ip_mem->sio_ir.raw);
  1603. shadow = readl(&port->ip_serial_regs->shadow);
  1604. if ((port->ip_notify & N_DCTS)
  1605. && (port->ip_port)) {
  1606. the_port = port->ip_port;
  1607. the_port->icount.cts =
  1608. (shadow & IOC4_SHADOW_CTS) ? 1 : 0;
  1609. wake_up_interruptible
  1610. (&the_port->info->delta_msr_wait);
  1611. }
  1612. }
  1613. /* rx timeout interrupt. Must be some data available. Put this
  1614. * before the check for rx_high since servicing this condition
  1615. * may cause that condition to clear.
  1616. */
  1617. if (sio_ir & hooks->intr_rx_timer) {
  1618. /* ACK the interrupt */
  1619. writel(hooks->intr_rx_timer,
  1620. &port->ip_mem->sio_ir.raw);
  1621. if ((port->ip_notify & N_DATA_READY)
  1622. && (port->ip_port)) {
  1623. /* ip_lock is set on call here */
  1624. receive_chars(port->ip_port);
  1625. }
  1626. }
  1627. /* rx high interrupt. Must be after rx_timer. */
  1628. else if (sio_ir & hooks->intr_rx_high) {
  1629. /* Data available, notify upper layer */
  1630. if ((port->ip_notify & N_DATA_READY)
  1631. && port->ip_port) {
  1632. /* ip_lock is set on call here */
  1633. receive_chars(port->ip_port);
  1634. }
  1635. /* We can't ACK this interrupt. If receive_chars didn't
  1636. * cause the condition to clear, we'll have to disable
  1637. * the interrupt until the data is drained.
  1638. * If the read was aborted, don't disable the interrupt
  1639. * as this may cause us to hang indefinitely. An
  1640. * aborted read generally means that this interrupt
  1641. * hasn't been delivered to the cpu yet anyway, even
  1642. * though we see it as asserted when we read the sio_ir.
  1643. */
  1644. if ((sio_ir = PENDING(port)) & hooks->intr_rx_high) {
  1645. if ((port->ip_flags & READ_ABORTED) == 0) {
  1646. port->ip_ienb &= ~hooks->intr_rx_high;
  1647. port->ip_flags |= INPUT_HIGH;
  1648. } else {
  1649. rx_high_rd_aborted++;
  1650. }
  1651. }
  1652. }
  1653. /* We got a low water interrupt: notify upper layer to
  1654. * send more data. Must come before tx_mt since servicing
  1655. * this condition may cause that condition to clear.
  1656. */
  1657. if (sio_ir & hooks->intr_tx_explicit) {
  1658. port->ip_flags &= ~LOWAT_WRITTEN;
  1659. /* ACK the interrupt */
  1660. writel(hooks->intr_tx_explicit,
  1661. &port->ip_mem->sio_ir.raw);
  1662. if (port->ip_notify & N_OUTPUT_LOWAT)
  1663. ioc4_cb_output_lowat(port);
  1664. }
  1665. /* Handle tx_mt. Must come after tx_explicit. */
  1666. else if (sio_ir & hooks->intr_tx_mt) {
  1667. /* If we are expecting a lowat notification
  1668. * and we get to this point it probably means that for
  1669. * some reason the tx_explicit didn't work as expected
  1670. * (that can legitimately happen if the output buffer is
  1671. * filled up in just the right way).
  1672. * So send the notification now.
  1673. */
  1674. if (port->ip_notify & N_OUTPUT_LOWAT) {
  1675. ioc4_cb_output_lowat(port);
  1676. /* We need to reload the sio_ir since the lowat
  1677. * call may have caused another write to occur,
  1678. * clearing the tx_mt condition.
  1679. */
  1680. sio_ir = PENDING(port);
  1681. }
  1682. /* If the tx_mt condition still persists even after the
  1683. * lowat call, we've got some work to do.
  1684. */
  1685. if (sio_ir & hooks->intr_tx_mt) {
  1686. /* If we are not currently expecting DMA input,
  1687. * and the transmitter has just gone idle,
  1688. * there is no longer any reason for DMA, so
  1689. * disable it.
  1690. */
  1691. if (!(port->ip_notify
  1692. & (N_DATA_READY | N_DDCD))) {
  1693. BUG_ON(!(port->ip_sscr
  1694. & IOC4_SSCR_DMA_EN));
  1695. port->ip_sscr &= ~IOC4_SSCR_DMA_EN;
  1696. writel(port->ip_sscr,
  1697. &port->ip_serial_regs->sscr);
  1698. }
  1699. /* Prevent infinite tx_mt interrupt */
  1700. port->ip_ienb &= ~hooks->intr_tx_mt;
  1701. }
  1702. }
  1703. sio_ir = PENDING(port);
  1704. /* if the read was aborted and only hooks->intr_rx_high,
  1705. * clear hooks->intr_rx_high, so we do not loop forever.
  1706. */
  1707. if (rx_high_rd_aborted && (sio_ir == hooks->intr_rx_high)) {
  1708. sio_ir &= ~hooks->intr_rx_high;
  1709. }
  1710. } while (sio_ir & hooks->intr_all);
  1711. spin_unlock_irqrestore(&port->ip_lock, flags);
  1712. /* Re-enable interrupts before returning from interrupt handler.
  1713. * Getting interrupted here is okay. It'll just v() our semaphore, and
  1714. * we'll come through the loop again.
  1715. */
  1716. write_ireg(port->ip_ioc4_soft, port->ip_ienb, IOC4_W_IES,
  1717. IOC4_SIO_INTR_TYPE);
  1718. }
  1719. /*
  1720. * ioc4_cb_post_ncs - called for some basic errors
  1721. * @port: port to use
  1722. * @ncs: event
  1723. */
  1724. static void ioc4_cb_post_ncs(struct uart_port *the_port, int ncs)
  1725. {
  1726. struct uart_icount *icount;
  1727. icount = &the_port->icount;
  1728. if (ncs & NCS_BREAK)
  1729. icount->brk++;
  1730. if (ncs & NCS_FRAMING)
  1731. icount->frame++;
  1732. if (ncs & NCS_OVERRUN)
  1733. icount->overrun++;
  1734. if (ncs & NCS_PARITY)
  1735. icount->parity++;
  1736. }
  1737. /**
  1738. * do_read - Read in bytes from the port. Return the number of bytes
  1739. * actually read.
  1740. * @the_port: port to use
  1741. * @buf: place to put the stuff we read
  1742. * @len: how big 'buf' is
  1743. */
  1744. static inline int do_read(struct uart_port *the_port, unsigned char *buf,
  1745. int len)
  1746. {
  1747. int prod_ptr, cons_ptr, total;
  1748. struct ioc4_port *port = get_ioc4_port(the_port);
  1749. struct ring *inring;
  1750. struct ring_entry *entry;
  1751. struct hooks *hooks = port->ip_hooks;
  1752. int byte_num;
  1753. char *sc;
  1754. int loop_counter;
  1755. BUG_ON(!(len >= 0));
  1756. BUG_ON(!port);
  1757. /* There is a nasty timing issue in the IOC4. When the rx_timer
  1758. * expires or the rx_high condition arises, we take an interrupt.
  1759. * At some point while servicing the interrupt, we read bytes from
  1760. * the ring buffer and re-arm the rx_timer. However the rx_timer is
  1761. * not started until the first byte is received *after* it is armed,
  1762. * and any bytes pending in the rx construction buffers are not drained
  1763. * to memory until either there are 4 bytes available or the rx_timer
  1764. * expires. This leads to a potential situation where data is left
  1765. * in the construction buffers forever - 1 to 3 bytes were received
  1766. * after the interrupt was generated but before the rx_timer was
  1767. * re-armed. At that point as long as no subsequent bytes are received
  1768. * the timer will never be started and the bytes will remain in the
  1769. * construction buffer forever. The solution is to execute a DRAIN
  1770. * command after rearming the timer. This way any bytes received before
  1771. * the DRAIN will be drained to memory, and any bytes received after
  1772. * the DRAIN will start the TIMER and be drained when it expires.
  1773. * Luckily, this only needs to be done when the DMA buffer is empty
  1774. * since there is no requirement that this function return all
  1775. * available data as long as it returns some.
  1776. */
  1777. /* Re-arm the timer */
  1778. writel(port->ip_rx_cons | IOC4_SRCIR_ARM, &port->ip_serial_regs->srcir);
  1779. prod_ptr = readl(&port->ip_serial_regs->srpir) & PROD_CONS_MASK;
  1780. cons_ptr = port->ip_rx_cons;
  1781. if (prod_ptr == cons_ptr) {
  1782. int reset_dma = 0;
  1783. /* Input buffer appears empty, do a flush. */
  1784. /* DMA must be enabled for this to work. */
  1785. if (!(port->ip_sscr & IOC4_SSCR_DMA_EN)) {
  1786. port->ip_sscr |= IOC4_SSCR_DMA_EN;
  1787. reset_dma = 1;
  1788. }
  1789. /* Potential race condition: we must reload the srpir after
  1790. * issuing the drain command, otherwise we could think the rx
  1791. * buffer is empty, then take a very long interrupt, and when
  1792. * we come back it's full and we wait forever for the drain to
  1793. * complete.
  1794. */
  1795. writel(port->ip_sscr | IOC4_SSCR_RX_DRAIN,
  1796. &port->ip_serial_regs->sscr);
  1797. prod_ptr = readl(&port->ip_serial_regs->srpir)
  1798. & PROD_CONS_MASK;
  1799. /* We must not wait for the DRAIN to complete unless there are
  1800. * at least 8 bytes (2 ring entries) available to receive the
  1801. * data otherwise the DRAIN will never complete and we'll
  1802. * deadlock here.
  1803. * In fact, to make things easier, I'll just ignore the flush if
  1804. * there is any data at all now available.
  1805. */
  1806. if (prod_ptr == cons_ptr) {
  1807. loop_counter = 0;
  1808. while (readl(&port->ip_serial_regs->sscr) &
  1809. IOC4_SSCR_RX_DRAIN) {
  1810. loop_counter++;
  1811. if (loop_counter > MAXITER)
  1812. return -1;
  1813. }
  1814. /* SIGH. We have to reload the prod_ptr *again* since
  1815. * the drain may have caused it to change
  1816. */
  1817. prod_ptr = readl(&port->ip_serial_regs->srpir)
  1818. & PROD_CONS_MASK;
  1819. }
  1820. if (reset_dma) {
  1821. port->ip_sscr &= ~IOC4_SSCR_DMA_EN;
  1822. writel(port->ip_sscr, &port->ip_serial_regs->sscr);
  1823. }
  1824. }
  1825. inring = port->ip_inring;
  1826. port->ip_flags &= ~READ_ABORTED;
  1827. total = 0;
  1828. loop_counter = 0xfffff; /* to avoid hangs */
  1829. /* Grab bytes from the hardware */
  1830. while ((prod_ptr != cons_ptr) && (len > 0)) {
  1831. entry = (struct ring_entry *)((caddr_t)inring + cons_ptr);
  1832. if ( loop_counter-- <= 0 ) {
  1833. printk(KERN_WARNING "IOC4 serial: "
  1834. "possible hang condition/"
  1835. "port stuck on read.\n");
  1836. break;
  1837. }
  1838. /* According to the producer pointer, this ring entry
  1839. * must contain some data. But if the PIO happened faster
  1840. * than the DMA, the data may not be available yet, so let's
  1841. * wait until it arrives.
  1842. */
  1843. if ((entry->ring_allsc & RING_ANY_VALID) == 0) {
  1844. /* Indicate the read is aborted so we don't disable
  1845. * the interrupt thinking that the consumer is
  1846. * congested.
  1847. */
  1848. port->ip_flags |= READ_ABORTED;
  1849. len = 0;
  1850. break;
  1851. }
  1852. /* Load the bytes/status out of the ring entry */
  1853. for (byte_num = 0; byte_num < 4 && len > 0; byte_num++) {
  1854. sc = &(entry->ring_sc[byte_num]);
  1855. /* Check for change in modem state or overrun */
  1856. if ((*sc & IOC4_RXSB_MODEM_VALID)
  1857. && (port->ip_notify & N_DDCD)) {
  1858. /* Notify upper layer if DCD dropped */
  1859. if ((port->ip_flags & DCD_ON)
  1860. && !(*sc & IOC4_RXSB_DCD)) {
  1861. /* If we have already copied some data,
  1862. * return it. We'll pick up the carrier
  1863. * drop on the next pass. That way we
  1864. * don't throw away the data that has
  1865. * already been copied back to
  1866. * the caller's buffer.
  1867. */
  1868. if (total > 0) {
  1869. len = 0;
  1870. break;
  1871. }
  1872. port->ip_flags &= ~DCD_ON;
  1873. /* Turn off this notification so the
  1874. * carrier drop protocol won't see it
  1875. * again when it does a read.
  1876. */
  1877. *sc &= ~IOC4_RXSB_MODEM_VALID;
  1878. /* To keep things consistent, we need
  1879. * to update the consumer pointer so
  1880. * the next reader won't come in and
  1881. * try to read the same ring entries
  1882. * again. This must be done here before
  1883. * the dcd change.
  1884. */
  1885. if ((entry->ring_allsc & RING_ANY_VALID)
  1886. == 0) {
  1887. cons_ptr += (int)sizeof
  1888. (struct ring_entry);
  1889. cons_ptr &= PROD_CONS_MASK;
  1890. }
  1891. writel(cons_ptr,
  1892. &port->ip_serial_regs->srcir);
  1893. port->ip_rx_cons = cons_ptr;
  1894. /* Notify upper layer of carrier drop */
  1895. if ((port->ip_notify & N_DDCD)
  1896. && port->ip_port) {
  1897. the_port->icount.dcd = 0;
  1898. wake_up_interruptible
  1899. (&the_port->info->
  1900. delta_msr_wait);
  1901. }
  1902. /* If we had any data to return, we
  1903. * would have returned it above.
  1904. */
  1905. return 0;
  1906. }
  1907. }
  1908. if (*sc & IOC4_RXSB_MODEM_VALID) {
  1909. /* Notify that an input overrun occurred */
  1910. if ((*sc & IOC4_RXSB_OVERRUN)
  1911. && (port->ip_notify & N_OVERRUN_ERROR)) {
  1912. ioc4_cb_post_ncs(the_port, NCS_OVERRUN);
  1913. }
  1914. /* Don't look at this byte again */
  1915. *sc &= ~IOC4_RXSB_MODEM_VALID;
  1916. }
  1917. /* Check for valid data or RX errors */
  1918. if ((*sc & IOC4_RXSB_DATA_VALID) &&
  1919. ((*sc & (IOC4_RXSB_PAR_ERR
  1920. | IOC4_RXSB_FRAME_ERR
  1921. | IOC4_RXSB_BREAK))
  1922. && (port->ip_notify & (N_PARITY_ERROR
  1923. | N_FRAMING_ERROR
  1924. | N_BREAK)))) {
  1925. /* There is an error condition on the next byte.
  1926. * If we have already transferred some bytes,
  1927. * we'll stop here. Otherwise if this is the
  1928. * first byte to be read, we'll just transfer
  1929. * it alone after notifying the
  1930. * upper layer of its status.
  1931. */
  1932. if (total > 0) {
  1933. len = 0;
  1934. break;
  1935. } else {
  1936. if ((*sc & IOC4_RXSB_PAR_ERR) &&
  1937. (port->ip_notify & N_PARITY_ERROR)) {
  1938. ioc4_cb_post_ncs(the_port,
  1939. NCS_PARITY);
  1940. }
  1941. if ((*sc & IOC4_RXSB_FRAME_ERR) &&
  1942. (port->ip_notify & N_FRAMING_ERROR)){
  1943. ioc4_cb_post_ncs(the_port,
  1944. NCS_FRAMING);
  1945. }
  1946. if ((*sc & IOC4_RXSB_BREAK)
  1947. && (port->ip_notify & N_BREAK)) {
  1948. ioc4_cb_post_ncs
  1949. (the_port,
  1950. NCS_BREAK);
  1951. }
  1952. len = 1;
  1953. }
  1954. }
  1955. if (*sc & IOC4_RXSB_DATA_VALID) {
  1956. *sc &= ~IOC4_RXSB_DATA_VALID;
  1957. *buf = entry->ring_data[byte_num];
  1958. buf++;
  1959. len--;
  1960. total++;
  1961. }
  1962. }
  1963. /* If we used up this entry entirely, go on to the next one,
  1964. * otherwise we must have run out of buffer space, so
  1965. * leave the consumer pointer here for the next read in case
  1966. * there are still unread bytes in this entry.
  1967. */
  1968. if ((entry->ring_allsc & RING_ANY_VALID) == 0) {
  1969. cons_ptr += (int)sizeof(struct ring_entry);
  1970. cons_ptr &= PROD_CONS_MASK;
  1971. }
  1972. }
  1973. /* Update consumer pointer and re-arm rx timer interrupt */
  1974. writel(cons_ptr, &port->ip_serial_regs->srcir);
  1975. port->ip_rx_cons = cons_ptr;
  1976. /* If we have now dipped below the rx high water mark and we have
  1977. * rx_high interrupt turned off, we can now turn it back on again.
  1978. */
  1979. if ((port->ip_flags & INPUT_HIGH) && (((prod_ptr - cons_ptr)
  1980. & PROD_CONS_MASK) < ((port->ip_sscr &
  1981. IOC4_SSCR_RX_THRESHOLD)
  1982. << IOC4_PROD_CONS_PTR_OFF))) {
  1983. port->ip_flags &= ~INPUT_HIGH;
  1984. enable_intrs(port, hooks->intr_rx_high);
  1985. }
  1986. return total;
  1987. }
  1988. /**
  1989. * receive_chars - upper level read. Called with ip_lock.
  1990. * @the_port: port to read from
  1991. */
  1992. static void receive_chars(struct uart_port *the_port)
  1993. {
  1994. struct tty_struct *tty;
  1995. unsigned char ch[IOC4_MAX_CHARS];
  1996. int read_count, request_count = IOC4_MAX_CHARS;
  1997. struct uart_icount *icount;
  1998. struct uart_info *info = the_port->info;
  1999. unsigned long pflags;
  2000. /* Make sure all the pointers are "good" ones */
  2001. if (!info)
  2002. return;
  2003. if (!info->tty)
  2004. return;
  2005. spin_lock_irqsave(&the_port->lock, pflags);
  2006. tty = info->tty;
  2007. request_count = tty_buffer_request_room(tty, IOC4_MAX_CHARS);
  2008. if (request_count > 0) {
  2009. icount = &the_port->icount;
  2010. read_count = do_read(the_port, ch, request_count);
  2011. if (read_count > 0) {
  2012. tty_insert_flip_string(tty, ch, read_count);
  2013. icount->rx += read_count;
  2014. }
  2015. }
  2016. spin_unlock_irqrestore(&the_port->lock, pflags);
  2017. tty_flip_buffer_push(tty);
  2018. }
  2019. /**
  2020. * ic4_type - What type of console are we?
  2021. * @port: Port to operate with (we ignore since we only have one port)
  2022. *
  2023. */
  2024. static const char *ic4_type(struct uart_port *the_port)
  2025. {
  2026. return "SGI IOC4 Serial";
  2027. }
  2028. /**
  2029. * ic4_tx_empty - Is the transmitter empty? We pretend we're always empty
  2030. * @port: Port to operate on (we ignore since we always return 1)
  2031. *
  2032. */
  2033. static unsigned int ic4_tx_empty(struct uart_port *the_port)
  2034. {
  2035. return 1;
  2036. }
  2037. /**
  2038. * ic4_stop_tx - stop the transmitter
  2039. * @port: Port to operate on
  2040. *
  2041. */
  2042. static void ic4_stop_tx(struct uart_port *the_port)
  2043. {
  2044. }
  2045. /**
  2046. * null_void_function -
  2047. * @port: Port to operate on
  2048. *
  2049. */
  2050. static void null_void_function(struct uart_port *the_port)
  2051. {
  2052. }
  2053. /**
  2054. * ic4_shutdown - shut down the port - free irq and disable
  2055. * @port: Port to shut down
  2056. *
  2057. */
  2058. static void ic4_shutdown(struct uart_port *the_port)
  2059. {
  2060. unsigned long port_flags;
  2061. struct ioc4_port *port;
  2062. struct uart_info *info;
  2063. port = get_ioc4_port(the_port);
  2064. if (!port)
  2065. return;
  2066. info = the_port->info;
  2067. wake_up_interruptible(&info->delta_msr_wait);
  2068. if (info->tty)
  2069. set_bit(TTY_IO_ERROR, &info->tty->flags);
  2070. spin_lock_irqsave(&the_port->lock, port_flags);
  2071. set_notification(port, N_ALL, 0);
  2072. spin_unlock_irqrestore(&the_port->lock, port_flags);
  2073. }
  2074. /**
  2075. * ic4_set_mctrl - set control lines (dtr, rts, etc)
  2076. * @port: Port to operate on
  2077. * @mctrl: Lines to set/unset
  2078. *
  2079. */
  2080. static void ic4_set_mctrl(struct uart_port *the_port, unsigned int mctrl)
  2081. {
  2082. unsigned char mcr = 0;
  2083. if (mctrl & TIOCM_RTS)
  2084. mcr |= UART_MCR_RTS;
  2085. if (mctrl & TIOCM_DTR)
  2086. mcr |= UART_MCR_DTR;
  2087. if (mctrl & TIOCM_OUT1)
  2088. mcr |= UART_MCR_OUT1;
  2089. if (mctrl & TIOCM_OUT2)
  2090. mcr |= UART_MCR_OUT2;
  2091. if (mctrl & TIOCM_LOOP)
  2092. mcr |= UART_MCR_LOOP;
  2093. set_mcr(the_port, 1, mcr, IOC4_SHADOW_DTR);
  2094. }
  2095. /**
  2096. * ic4_get_mctrl - get control line info
  2097. * @port: port to operate on
  2098. *
  2099. */
  2100. static unsigned int ic4_get_mctrl(struct uart_port *the_port)
  2101. {
  2102. struct ioc4_port *port = get_ioc4_port(the_port);
  2103. uint32_t shadow;
  2104. unsigned int ret = 0;
  2105. if (!port)
  2106. return 0;
  2107. shadow = readl(&port->ip_serial_regs->shadow);
  2108. if (shadow & IOC4_SHADOW_DCD)
  2109. ret |= TIOCM_CAR;
  2110. if (shadow & IOC4_SHADOW_DR)
  2111. ret |= TIOCM_DSR;
  2112. if (shadow & IOC4_SHADOW_CTS)
  2113. ret |= TIOCM_CTS;
  2114. return ret;
  2115. }
  2116. /**
  2117. * ic4_start_tx - Start transmitter, flush any output
  2118. * @port: Port to operate on
  2119. *
  2120. */
  2121. static void ic4_start_tx(struct uart_port *the_port)
  2122. {
  2123. struct ioc4_port *port = get_ioc4_port(the_port);
  2124. if (port) {
  2125. set_notification(port, N_OUTPUT_LOWAT, 1);
  2126. enable_intrs(port, port->ip_hooks->intr_tx_mt);
  2127. }
  2128. }
  2129. /**
  2130. * ic4_break_ctl - handle breaks
  2131. * @port: Port to operate on
  2132. * @break_state: Break state
  2133. *
  2134. */
  2135. static void ic4_break_ctl(struct uart_port *the_port, int break_state)
  2136. {
  2137. }
  2138. /**
  2139. * ic4_startup - Start up the serial port - always return 0 (We're always on)
  2140. * @port: Port to operate on
  2141. *
  2142. */
  2143. static int ic4_startup(struct uart_port *the_port)
  2144. {
  2145. int retval;
  2146. struct ioc4_port *port;
  2147. struct ioc4_control *control;
  2148. struct uart_info *info;
  2149. unsigned long port_flags;
  2150. if (!the_port) {
  2151. return -ENODEV;
  2152. }
  2153. port = get_ioc4_port(the_port);
  2154. if (!port) {
  2155. return -ENODEV;
  2156. }
  2157. info = the_port->info;
  2158. control = port->ip_control;
  2159. if (!control) {
  2160. return -ENODEV;
  2161. }
  2162. /* Start up the serial port */
  2163. spin_lock_irqsave(&the_port->lock, port_flags);
  2164. retval = ic4_startup_local(the_port);
  2165. spin_unlock_irqrestore(&the_port->lock, port_flags);
  2166. return retval;
  2167. }
  2168. /**
  2169. * ic4_set_termios - set termios stuff
  2170. * @port: port to operate on
  2171. * @termios: New settings
  2172. * @termios: Old
  2173. *
  2174. */
  2175. static void
  2176. ic4_set_termios(struct uart_port *the_port,
  2177. struct termios *termios, struct termios *old_termios)
  2178. {
  2179. unsigned long port_flags;
  2180. spin_lock_irqsave(&the_port->lock, port_flags);
  2181. ioc4_change_speed(the_port, termios, old_termios);
  2182. spin_unlock_irqrestore(&the_port->lock, port_flags);
  2183. }
  2184. /**
  2185. * ic4_request_port - allocate resources for port - no op....
  2186. * @port: port to operate on
  2187. *
  2188. */
  2189. static int ic4_request_port(struct uart_port *port)
  2190. {
  2191. return 0;
  2192. }
  2193. /* Associate the uart functions above - given to serial core */
  2194. static struct uart_ops ioc4_ops = {
  2195. .tx_empty = ic4_tx_empty,
  2196. .set_mctrl = ic4_set_mctrl,
  2197. .get_mctrl = ic4_get_mctrl,
  2198. .stop_tx = ic4_stop_tx,
  2199. .start_tx = ic4_start_tx,
  2200. .stop_rx = null_void_function,
  2201. .enable_ms = null_void_function,
  2202. .break_ctl = ic4_break_ctl,
  2203. .startup = ic4_startup,
  2204. .shutdown = ic4_shutdown,
  2205. .set_termios = ic4_set_termios,
  2206. .type = ic4_type,
  2207. .release_port = null_void_function,
  2208. .request_port = ic4_request_port,
  2209. };
  2210. /*
  2211. * Boot-time initialization code
  2212. */
  2213. static struct uart_driver ioc4_uart = {
  2214. .owner = THIS_MODULE,
  2215. .driver_name = "ioc4_serial",
  2216. .dev_name = DEVICE_NAME,
  2217. .major = DEVICE_MAJOR,
  2218. .minor = DEVICE_MINOR,
  2219. .nr = IOC4_NUM_CARDS * IOC4_NUM_SERIAL_PORTS,
  2220. };
  2221. /**
  2222. * ioc4_serial_core_attach - register with serial core
  2223. * This is done during pci probing
  2224. * @pdev: handle for this card
  2225. */
  2226. static inline int
  2227. ioc4_serial_core_attach(struct pci_dev *pdev)
  2228. {
  2229. struct ioc4_port *port;
  2230. struct uart_port *the_port;
  2231. struct ioc4_driver_data *idd = pci_get_drvdata(pdev);
  2232. struct ioc4_control *control = idd->idd_serial_data;
  2233. int ii;
  2234. DPRINT_CONFIG(("%s: attach pdev 0x%p - control 0x%p\n",
  2235. __FUNCTION__, pdev, (void *)control));
  2236. if (!control)
  2237. return -ENODEV;
  2238. /* once around for each port on this card */
  2239. for (ii = 0; ii < IOC4_NUM_SERIAL_PORTS; ii++) {
  2240. the_port = &control->ic_port[ii].icp_uart_port;
  2241. port = control->ic_port[ii].icp_port;
  2242. port->ip_port = the_port;
  2243. DPRINT_CONFIG(("%s: attach the_port 0x%p / port 0x%p\n",
  2244. __FUNCTION__, (void *)the_port,
  2245. (void *)port));
  2246. /* membase, iobase and mapbase just need to be non-0 */
  2247. the_port->membase = (unsigned char __iomem *)1;
  2248. the_port->iobase = (pdev->bus->number << 16) | ii;
  2249. the_port->line = (Num_of_ioc4_cards << 2) | ii;
  2250. the_port->mapbase = 1;
  2251. the_port->type = PORT_16550A;
  2252. the_port->fifosize = IOC4_FIFO_CHARS;
  2253. the_port->ops = &ioc4_ops;
  2254. the_port->irq = control->ic_irq;
  2255. the_port->dev = &pdev->dev;
  2256. spin_lock_init(&the_port->lock);
  2257. if (uart_add_one_port(&ioc4_uart, the_port) < 0) {
  2258. printk(KERN_WARNING
  2259. "%s: unable to add port %d bus %d\n",
  2260. __FUNCTION__, the_port->line, pdev->bus->number);
  2261. } else {
  2262. DPRINT_CONFIG(
  2263. ("IOC4 serial port %d irq = %d, bus %d\n",
  2264. the_port->line, the_port->irq, pdev->bus->number));
  2265. }
  2266. /* all ports are rs232 for now */
  2267. ioc4_set_proto(port, PROTO_RS232);
  2268. }
  2269. return 0;
  2270. }
  2271. /**
  2272. * ioc4_serial_attach_one - register attach function
  2273. * called per card found from IOC4 master module.
  2274. * @idd: Master module data for this IOC4
  2275. */
  2276. int
  2277. ioc4_serial_attach_one(struct ioc4_driver_data *idd)
  2278. {
  2279. unsigned long tmp_addr1;
  2280. struct ioc4_serial __iomem *serial;
  2281. struct ioc4_soft *soft;
  2282. struct ioc4_control *control;
  2283. int ret = 0;
  2284. DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __FUNCTION__, idd->idd_pdev, idd->idd_pci_id));
  2285. /* request serial registers */
  2286. tmp_addr1 = idd->idd_bar0 + IOC4_SERIAL_OFFSET;
  2287. if (!request_region(tmp_addr1, sizeof(struct ioc4_serial),
  2288. "sioc4_uart")) {
  2289. printk(KERN_WARNING
  2290. "ioc4 (%p): unable to get request region for "
  2291. "uart space\n", (void *)idd->idd_pdev);
  2292. ret = -ENODEV;
  2293. goto out1;
  2294. }
  2295. serial = ioremap(tmp_addr1, sizeof(struct ioc4_serial));
  2296. if (!serial) {
  2297. printk(KERN_WARNING
  2298. "ioc4 (%p) : unable to remap ioc4 serial register\n",
  2299. (void *)idd->idd_pdev);
  2300. ret = -ENODEV;
  2301. goto out2;
  2302. }
  2303. DPRINT_CONFIG(("%s : mem 0x%p, serial 0x%p\n",
  2304. __FUNCTION__, (void *)idd->idd_misc_regs, (void *)serial));
  2305. /* Get memory for the new card */
  2306. control = kmalloc(sizeof(struct ioc4_control) * IOC4_NUM_SERIAL_PORTS,
  2307. GFP_KERNEL);
  2308. if (!control) {
  2309. printk(KERN_WARNING "ioc4_attach_one"
  2310. ": unable to get memory for the IOC4\n");
  2311. ret = -ENOMEM;
  2312. goto out2;
  2313. }
  2314. memset(control, 0, sizeof(struct ioc4_control));
  2315. idd->idd_serial_data = control;
  2316. /* Allocate the soft structure */
  2317. soft = kmalloc(sizeof(struct ioc4_soft), GFP_KERNEL);
  2318. if (!soft) {
  2319. printk(KERN_WARNING
  2320. "ioc4 (%p): unable to get memory for the soft struct\n",
  2321. (void *)idd->idd_pdev);
  2322. ret = -ENOMEM;
  2323. goto out3;
  2324. }
  2325. memset(soft, 0, sizeof(struct ioc4_soft));
  2326. spin_lock_init(&soft->is_ir_lock);
  2327. soft->is_ioc4_misc_addr = idd->idd_misc_regs;
  2328. soft->is_ioc4_serial_addr = serial;
  2329. /* Init the IOC4 */
  2330. writel(0xf << IOC4_SIO_CR_CMD_PULSE_SHIFT,
  2331. &idd->idd_misc_regs->sio_cr.raw);
  2332. /* Enable serial port mode select generic PIO pins as outputs */
  2333. writel(IOC4_GPCR_UART0_MODESEL | IOC4_GPCR_UART1_MODESEL
  2334. | IOC4_GPCR_UART2_MODESEL | IOC4_GPCR_UART3_MODESEL,
  2335. &idd->idd_misc_regs->gpcr_s.raw);
  2336. /* Clear and disable all serial interrupts */
  2337. write_ireg(soft, ~0, IOC4_W_IEC, IOC4_SIO_INTR_TYPE);
  2338. writel(~0, &idd->idd_misc_regs->sio_ir.raw);
  2339. write_ireg(soft, IOC4_OTHER_IR_SER_MEMERR, IOC4_W_IEC,
  2340. IOC4_OTHER_INTR_TYPE);
  2341. writel(IOC4_OTHER_IR_SER_MEMERR, &idd->idd_misc_regs->other_ir.raw);
  2342. control->ic_soft = soft;
  2343. /* Hook up interrupt handler */
  2344. if (!request_irq(idd->idd_pdev->irq, ioc4_intr, SA_SHIRQ,
  2345. "sgi-ioc4serial", (void *)soft)) {
  2346. control->ic_irq = idd->idd_pdev->irq;
  2347. } else {
  2348. printk(KERN_WARNING
  2349. "%s : request_irq fails for IRQ 0x%x\n ",
  2350. __FUNCTION__, idd->idd_pdev->irq);
  2351. }
  2352. ret = ioc4_attach_local(idd);
  2353. if (ret)
  2354. goto out4;
  2355. /* register port with the serial core */
  2356. if ((ret = ioc4_serial_core_attach(idd->idd_pdev)))
  2357. goto out4;
  2358. Num_of_ioc4_cards++;
  2359. return ret;
  2360. /* error exits that give back resources */
  2361. out4:
  2362. kfree(soft);
  2363. out3:
  2364. kfree(control);
  2365. out2:
  2366. release_region(tmp_addr1, sizeof(struct ioc4_serial));
  2367. out1:
  2368. return ret;
  2369. }
  2370. /**
  2371. * ioc4_serial_remove_one - detach function
  2372. *
  2373. * @idd: IOC4 master module data for this IOC4
  2374. */
  2375. int ioc4_serial_remove_one(struct ioc4_driver_data *idd)
  2376. {
  2377. int ii;
  2378. struct ioc4_control *control;
  2379. struct uart_port *the_port;
  2380. struct ioc4_port *port;
  2381. struct ioc4_soft *soft;
  2382. control = idd->idd_serial_data;
  2383. for (ii = 0; ii < IOC4_NUM_SERIAL_PORTS; ii++) {
  2384. the_port = &control->ic_port[ii].icp_uart_port;
  2385. if (the_port) {
  2386. uart_remove_one_port(&ioc4_uart, the_port);
  2387. }
  2388. port = control->ic_port[ii].icp_port;
  2389. if (!(ii & 1) && port) {
  2390. pci_free_consistent(port->ip_pdev,
  2391. TOTAL_RING_BUF_SIZE,
  2392. (void *)port->ip_cpu_ringbuf,
  2393. port->ip_dma_ringbuf);
  2394. kfree(port);
  2395. }
  2396. }
  2397. soft = control->ic_soft;
  2398. if (soft) {
  2399. free_irq(control->ic_irq, (void *)soft);
  2400. if (soft->is_ioc4_serial_addr) {
  2401. release_region((unsigned long)
  2402. soft->is_ioc4_serial_addr,
  2403. sizeof(struct ioc4_serial));
  2404. }
  2405. kfree(soft);
  2406. }
  2407. kfree(control);
  2408. idd->idd_serial_data = NULL;
  2409. return 0;
  2410. }
  2411. static struct ioc4_submodule ioc4_serial_submodule = {
  2412. .is_name = "IOC4_serial",
  2413. .is_owner = THIS_MODULE,
  2414. .is_probe = ioc4_serial_attach_one,
  2415. .is_remove = ioc4_serial_remove_one,
  2416. };
  2417. /**
  2418. * ioc4_serial_init - module init
  2419. */
  2420. int ioc4_serial_init(void)
  2421. {
  2422. int ret;
  2423. /* register with serial core */
  2424. if ((ret = uart_register_driver(&ioc4_uart)) < 0) {
  2425. printk(KERN_WARNING
  2426. "%s: Couldn't register IOC4 serial driver\n",
  2427. __FUNCTION__);
  2428. return ret;
  2429. }
  2430. /* register with IOC4 main module */
  2431. return ioc4_register_submodule(&ioc4_serial_submodule);
  2432. }
  2433. static void __devexit ioc4_serial_exit(void)
  2434. {
  2435. ioc4_unregister_submodule(&ioc4_serial_submodule);
  2436. uart_unregister_driver(&ioc4_uart);
  2437. }
  2438. module_init(ioc4_serial_init);
  2439. module_exit(ioc4_serial_exit);
  2440. MODULE_AUTHOR("Pat Gefre - Silicon Graphics Inc. (SGI) <pfg@sgi.com>");
  2441. MODULE_DESCRIPTION("Serial PCI driver module for SGI IOC4 Base-IO Card");
  2442. MODULE_LICENSE("GPL");