ioc4_serial.c 79 KB

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