12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432 |
-
-
- FILE_LICENCE ( GPL2_OR_LATER );
-
- #include <stdint.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <unistd.h>
- #include <assert.h>
- #include <ipxe/io.h>
- #include <ipxe/pci.h>
- #include <ipxe/infiniband.h>
- #include <ipxe/i2c.h>
- #include <ipxe/bitbash.h>
- #include <ipxe/malloc.h>
- #include <ipxe/iobuf.h>
- #include <ipxe/pcibackup.h>
- #include "qib7322.h"
-
-
-
-
- struct qib7322_send_buffers {
-
- unsigned long base;
-
- unsigned int size;
-
- unsigned int start;
-
-
- unsigned int count;
-
- unsigned int prod;
-
- unsigned int cons;
-
- uint16_t avail[0];
- };
-
-
- struct qib7322_send_work_queue {
-
- struct qib7322_send_buffers *send_bufs;
-
- uint16_t *used;
-
- unsigned int prod;
-
- unsigned int cons;
- };
-
-
- struct qib7322_recv_work_queue {
-
- void *header;
-
- struct QIB_7322_scalar header_prod;
-
- unsigned int header_cons;
-
- unsigned long eager_array;
-
- unsigned int eager_entries;
-
- unsigned int eager_prod;
-
- unsigned int eager_cons;
- };
-
-
- struct qib7322 {
-
- void *regs;
-
-
- uint8_t used_ctx[QIB7322_NUM_CONTEXTS];
-
- struct qib7322_send_work_queue send_wq[QIB7322_NUM_CONTEXTS];
-
- struct qib7322_recv_work_queue recv_wq[QIB7322_NUM_CONTEXTS];
-
-
- struct QIB_7322_SendBufAvail *sendbufavail;
-
- struct qib7322_send_buffers *send_bufs_small;
-
- struct qib7322_send_buffers *send_bufs_vl15_port0;
-
- struct qib7322_send_buffers *send_bufs_vl15_port1;
-
-
- struct i2c_bit_basher i2c;
-
- struct i2c_device eeprom;
-
-
- struct ib_gid_half guid;
-
- struct ib_device *ibdev[QIB7322_MAX_PORTS];
- };
-
-
-
-
- static void qib7322_readq ( struct qib7322 *qib7322, uint32_t *dwords,
- unsigned long offset ) {
- void *addr = ( qib7322->regs + offset );
-
- __asm__ __volatile__ ( "movq (%1), %%mm0\n\t"
- "movq %%mm0, (%0)\n\t"
- : : "r" ( dwords ), "r" ( addr ) : "memory" );
-
- DBGIO ( "[%08lx] => %08x%08x\n",
- virt_to_phys ( addr ), dwords[1], dwords[0] );
- }
- #define qib7322_readq( _qib7322, _ptr, _offset ) \
- qib7322_readq ( (_qib7322), (_ptr)->u.dwords, (_offset) )
- #define qib7322_readq_array8b( _qib7322, _ptr, _offset, _idx ) \
- qib7322_readq ( (_qib7322), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) )
- #define qib7322_readq_array64k( _qib7322, _ptr, _offset, _idx ) \
- qib7322_readq ( (_qib7322), (_ptr), ( (_offset) + ( (_idx) * 65536 ) ) )
- #define qib7322_readq_port( _qib7322, _ptr, _offset, _port ) \
- qib7322_readq ( (_qib7322), (_ptr), ( (_offset) + ( (_port) * 4096 ) ) )
-
-
- static void qib7322_writeq ( struct qib7322 *qib7322, const uint32_t *dwords,
- unsigned long offset ) {
- void *addr = ( qib7322->regs + offset );
-
- DBGIO ( "[%08lx] <= %08x%08x\n",
- virt_to_phys ( addr ), dwords[1], dwords[0] );
-
- __asm__ __volatile__ ( "movq (%0), %%mm0\n\t"
- "movq %%mm0, (%1)\n\t"
- : : "r" ( dwords ), "r" ( addr ) : "memory" );
- }
- #define qib7322_writeq( _qib7322, _ptr, _offset ) \
- qib7322_writeq ( (_qib7322), (_ptr)->u.dwords, (_offset) )
- #define qib7322_writeq_array8b( _qib7322, _ptr, _offset, _idx ) \
- qib7322_writeq ( (_qib7322), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) )
- #define qib7322_writeq_array64k( _qib7322, _ptr, _offset, _idx ) \
- qib7322_writeq ( (_qib7322), (_ptr), ( (_offset) + ( (_idx) * 65536 ) ))
- #define qib7322_writeq_port( _qib7322, _ptr, _offset, _port ) \
- qib7322_writeq ( (_qib7322), (_ptr), ( (_offset) + ( (_port) * 4096 ) ))
-
-
- static void qib7322_writel ( struct qib7322 *qib7322, uint32_t dword,
- unsigned long offset ) {
- writel ( dword, ( qib7322->regs + offset ) );
- }
-
-
-
-
- static const char * qib7322_link_state_text ( unsigned int link_state ) {
- switch ( link_state ) {
- case QIB7322_LINK_STATE_DOWN: return "DOWN";
- case QIB7322_LINK_STATE_INIT: return "INIT";
- case QIB7322_LINK_STATE_ARM: return "ARM";
- case QIB7322_LINK_STATE_ACTIVE: return "ACTIVE";
- case QIB7322_LINK_STATE_ACT_DEFER: return "ACT_DEFER";
- default: return "UNKNOWN";
- }
- }
-
-
- static void qib7322_link_state_changed ( struct ib_device *ibdev ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct QIB_7322_IBCStatusA_0 ibcstatusa;
- struct QIB_7322_EXTCtrl extctrl;
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
- unsigned int link_training_state;
- unsigned int link_state;
- unsigned int link_width;
- unsigned int link_speed;
- unsigned int link_speed_qdr;
- unsigned int green;
- unsigned int yellow;
-
-
- qib7322_readq_port ( qib7322, &ibcstatusa,
- QIB_7322_IBCStatusA_0_offset, port );
- link_training_state = BIT_GET ( &ibcstatusa, LinkTrainingState );
- link_state = BIT_GET ( &ibcstatusa, LinkState );
- link_width = BIT_GET ( &ibcstatusa, LinkWidthActive );
- link_speed = BIT_GET ( &ibcstatusa, LinkSpeedActive );
- link_speed_qdr = BIT_GET ( &ibcstatusa, LinkSpeedQDR );
- DBGC ( qib7322, "QIB7322 %p port %d training state %#x link state %s "
- "(%s %s)\n", qib7322, port, link_training_state,
- qib7322_link_state_text ( link_state ),
- ( link_speed_qdr ? "QDR" : ( link_speed ? "DDR" : "SDR" ) ),
- ( link_width ? "x4" : "x1" ) );
-
-
- qib7322_readq ( qib7322, &extctrl, QIB_7322_EXTCtrl_offset );
- green = ( ( link_state >= QIB7322_LINK_STATE_INIT ) ? 1 : 0 );
- yellow = ( ( link_state >= QIB7322_LINK_STATE_ACTIVE ) ? 1 : 0 );
- if ( port == 0 ) {
- BIT_SET ( &extctrl, LEDPort0GreenOn, green );
- BIT_SET ( &extctrl, LEDPort0YellowOn, yellow );
- } else {
- BIT_SET ( &extctrl, LEDPort1GreenOn, green );
- BIT_SET ( &extctrl, LEDPort1YellowOn, yellow );
- }
- qib7322_writeq ( qib7322, &extctrl, QIB_7322_EXTCtrl_offset );
-
-
- ibdev->port_state = ( link_state + 1 );
- ibdev->link_width_active =
- ( link_width ? IB_LINK_WIDTH_4X : IB_LINK_WIDTH_1X );
- ibdev->link_speed_active =
- ( link_speed ? IB_LINK_SPEED_DDR : IB_LINK_SPEED_SDR );
- ib_link_state_changed ( ibdev );
- }
-
-
- static int qib7322_link_state_check ( struct ib_device *ibdev,
- unsigned int new_link_state ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct QIB_7322_IBCStatusA_0 ibcstatusa;
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
- unsigned int link_state;
- unsigned int i;
-
- for ( i = 0 ; i < QIB7322_LINK_STATE_MAX_WAIT_US ; i++ ) {
- qib7322_readq_port ( qib7322, &ibcstatusa,
- QIB_7322_IBCStatusA_0_offset, port );
- link_state = BIT_GET ( &ibcstatusa, LinkState );
- if ( link_state == new_link_state )
- return 0;
- udelay ( 1 );
- }
-
- DBGC ( qib7322, "QIB7322 %p port %d timed out waiting for link state "
- "%s\n", qib7322, port, qib7322_link_state_text ( link_state ) );
- return -ETIMEDOUT;
- }
-
-
- static int qib7322_set_port_info ( struct ib_device *ibdev,
- union ib_mad *mad ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
- struct QIB_7322_IBCCtrlA_0 ibcctrla;
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
- unsigned int port_state;
- unsigned int link_state;
-
-
- port_state = ( port_info->link_speed_supported__port_state & 0xf );
- if ( port_state ) {
- link_state = ( port_state - 1 );
- DBGC ( qib7322, "QIB7322 %p set link state to %s (%x)\n",
- qib7322, qib7322_link_state_text ( link_state ),
- link_state );
- qib7322_readq_port ( qib7322, &ibcctrla,
- QIB_7322_IBCCtrlA_0_offset, port );
- BIT_SET ( &ibcctrla, LinkCmd, link_state );
- qib7322_writeq_port ( qib7322, &ibcctrla,
- QIB_7322_IBCCtrlA_0_offset, port );
-
-
-
- qib7322_link_state_check ( ibdev, link_state );
- }
-
-
- qib7322_link_state_changed ( ibdev );
-
- return 0;
- }
-
-
- static int qib7322_set_pkey_table ( struct ib_device *ibdev __unused,
- union ib_mad *mad __unused ) {
-
- return 0;
- }
-
-
-
-
- static int qib7322_alloc_ctx ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
- unsigned int ctx;
-
- for ( ctx = port ; ctx < QIB7322_NUM_CONTEXTS ; ctx += 2 ) {
-
- if ( ! qib7322->used_ctx[ctx] ) {
- qib7322->used_ctx[ctx] = 1;
- qp->qpn = ( ctx & ~0x01 );
- DBGC2 ( qib7322, "QIB7322 %p port %d QPN %ld is CTX "
- "%d\n", qib7322, port, qp->qpn, ctx );
- return 0;
- }
- }
-
- DBGC ( qib7322, "QIB7322 %p port %d out of available contexts\n",
- qib7322, port );
- return -ENOENT;
- }
-
-
- static unsigned int qib7322_ctx ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- return ( qp->qpn + ( ibdev->port - QIB7322_PORT_BASE ) );
- }
-
-
- static void qib7322_free_ctx ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
- unsigned int ctx = qib7322_ctx ( ibdev, qp );
-
- qib7322->used_ctx[ctx] = 0;
- DBGC2 ( qib7322, "QIB7322 %p port %d CTX %d freed\n",
- qib7322, port, ctx );
- }
-
-
-
-
- #define QIB7322_SEND_BUF_TOGGLE 0x8000
-
-
- static struct qib7322_send_buffers *
- qib7322_create_send_bufs ( struct qib7322 *qib7322, unsigned long base,
- unsigned int size, unsigned int start,
- unsigned int count ) {
- struct qib7322_send_buffers *send_bufs;
- unsigned int i;
-
-
- send_bufs = zalloc ( sizeof ( *send_bufs ) +
- ( count * sizeof ( send_bufs->avail[0] ) ) );
- if ( ! send_bufs )
- return NULL;
-
-
- send_bufs->base = base;
- send_bufs->size = size;
- send_bufs->start = start;
- send_bufs->count = count;
- for ( i = 0 ; i < count ; i++ )
- send_bufs->avail[i] = ( start + i );
-
- DBGC2 ( qib7322, "QIB7322 %p send buffer set %p [%d,%d] at %lx\n",
- qib7322, send_bufs, start, ( start + count - 1 ),
- send_bufs->base );
-
- return send_bufs;
- }
-
-
- static void qib7322_destroy_send_bufs ( struct qib7322 *qib7322 __unused,
- struct qib7322_send_buffers *send_bufs ){
- free ( send_bufs );
- }
-
-
- static int qib7322_alloc_send_buf ( struct qib7322 *qib7322,
- struct qib7322_send_buffers *send_bufs ) {
- unsigned int used;
- unsigned int mask;
- unsigned int send_buf;
-
- used = ( send_bufs->cons - send_bufs->prod );
- if ( used >= send_bufs->count ) {
- DBGC ( qib7322, "QIB7322 %p send buffer set %p out of "
- "buffers\n", qib7322, send_bufs );
- return -ENOBUFS;
- }
-
- mask = ( send_bufs->count - 1 );
- send_buf = send_bufs->avail[ send_bufs->cons++ & mask ];
- send_buf ^= QIB7322_SEND_BUF_TOGGLE;
- return send_buf;
- }
-
-
- static void qib7322_free_send_buf ( struct qib7322 *qib7322 __unused,
- struct qib7322_send_buffers *send_bufs,
- unsigned int send_buf ) {
- unsigned int mask;
-
- mask = ( send_bufs->count - 1 );
- send_bufs->avail[ send_bufs->prod++ & mask ] = send_buf;
- }
-
-
- static int qib7322_send_buf_in_use ( struct qib7322 *qib7322,
- unsigned int send_buf ) {
- unsigned int send_idx;
- unsigned int send_check;
- unsigned int inusecheck;
- unsigned int inuse;
- unsigned int check;
-
- send_idx = ( send_buf & ~QIB7322_SEND_BUF_TOGGLE );
- send_check = ( !! ( send_buf & QIB7322_SEND_BUF_TOGGLE ) );
- inusecheck = BIT_GET ( qib7322->sendbufavail, InUseCheck[send_idx] );
- inuse = ( !! ( inusecheck & 0x02 ) );
- check = ( !! ( inusecheck & 0x01 ) );
- return ( inuse || ( check != send_check ) );
- }
-
-
- static unsigned long
- qib7322_send_buffer_offset ( struct qib7322 *qib7322 __unused,
- struct qib7322_send_buffers *send_bufs,
- unsigned int send_buf ) {
- unsigned int index;
-
- index = ( ( send_buf & ~QIB7322_SEND_BUF_TOGGLE ) - send_bufs->start );
- return ( send_bufs->base + ( index * send_bufs->size ) );
- }
-
-
- static int qib7322_create_send_wq ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->send;
- struct qib7322_send_work_queue *qib7322_wq = ib_wq_get_drvdata ( wq );
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
-
-
- if ( qp->type == IB_QPT_SMI ) {
- if ( port == 0 ) {
- qib7322_wq->send_bufs = qib7322->send_bufs_vl15_port0;
- } else {
- qib7322_wq->send_bufs = qib7322->send_bufs_vl15_port1;
- }
- } else {
- qib7322_wq->send_bufs = qib7322->send_bufs_small;
- }
-
-
- qib7322_wq->used = zalloc ( qp->send.num_wqes *
- sizeof ( qib7322_wq->used[0] ) );
- if ( ! qib7322_wq->used )
- return -ENOMEM;
-
-
- qib7322_wq->prod = 0;
- qib7322_wq->cons = 0;
-
- return 0;
- }
-
-
- static void qib7322_destroy_send_wq ( struct ib_device *ibdev __unused,
- struct ib_queue_pair *qp ) {
- struct ib_work_queue *wq = &qp->send;
- struct qib7322_send_work_queue *qib7322_wq = ib_wq_get_drvdata ( wq );
-
- free ( qib7322_wq->used );
- }
-
-
- static int qib7322_init_send ( struct qib7322 *qib7322 ) {
- struct QIB_7322_SendBufBase sendbufbase;
- struct QIB_7322_SendBufAvailAddr sendbufavailaddr;
- struct QIB_7322_SendCtrl sendctrl;
- struct QIB_7322_SendCtrl_0 sendctrlp;
- unsigned long baseaddr_smallpio;
- unsigned long baseaddr_largepio;
- unsigned long baseaddr_vl15_port0;
- unsigned long baseaddr_vl15_port1;
- int rc;
-
-
- qib7322_readq ( qib7322, &sendbufbase, QIB_7322_SendBufBase_offset );
- baseaddr_smallpio = BIT_GET ( &sendbufbase, BaseAddr_SmallPIO );
- baseaddr_largepio = BIT_GET ( &sendbufbase, BaseAddr_LargePIO );
- baseaddr_vl15_port0 = ( baseaddr_largepio +
- ( QIB7322_LARGE_SEND_BUF_SIZE *
- QIB7322_LARGE_SEND_BUF_COUNT ) );
- baseaddr_vl15_port1 = ( baseaddr_vl15_port0 +
- QIB7322_VL15_PORT0_SEND_BUF_SIZE );
- qib7322->send_bufs_small =
- qib7322_create_send_bufs ( qib7322, baseaddr_smallpio,
- QIB7322_SMALL_SEND_BUF_SIZE,
- QIB7322_SMALL_SEND_BUF_START,
- QIB7322_SMALL_SEND_BUF_USED );
- if ( ! qib7322->send_bufs_small ) {
- rc = -ENOMEM;
- goto err_create_send_bufs_small;
- }
- qib7322->send_bufs_vl15_port0 =
- qib7322_create_send_bufs ( qib7322, baseaddr_vl15_port0,
- QIB7322_VL15_PORT0_SEND_BUF_SIZE,
- QIB7322_VL15_PORT0_SEND_BUF_START,
- QIB7322_VL15_PORT0_SEND_BUF_COUNT );
- if ( ! qib7322->send_bufs_vl15_port0 ) {
- rc = -ENOMEM;
- goto err_create_send_bufs_vl15_port0;
- }
- qib7322->send_bufs_vl15_port1 =
- qib7322_create_send_bufs ( qib7322, baseaddr_vl15_port1,
- QIB7322_VL15_PORT1_SEND_BUF_SIZE,
- QIB7322_VL15_PORT1_SEND_BUF_START,
- QIB7322_VL15_PORT1_SEND_BUF_COUNT );
- if ( ! qib7322->send_bufs_vl15_port1 ) {
- rc = -ENOMEM;
- goto err_create_send_bufs_vl15_port1;
- }
-
-
- qib7322->sendbufavail = malloc_dma ( sizeof ( *qib7322->sendbufavail ),
- QIB7322_SENDBUFAVAIL_ALIGN );
- if ( ! qib7322->sendbufavail ) {
- rc = -ENOMEM;
- goto err_alloc_sendbufavail;
- }
- memset ( qib7322->sendbufavail, 0, sizeof ( qib7322->sendbufavail ) );
-
-
- memset ( &sendbufavailaddr, 0, sizeof ( sendbufavailaddr ) );
- BIT_FILL_1 ( &sendbufavailaddr, SendBufAvailAddr,
- ( virt_to_bus ( qib7322->sendbufavail ) >> 6 ) );
- qib7322_writeq ( qib7322, &sendbufavailaddr,
- QIB_7322_SendBufAvailAddr_offset );
-
-
- memset ( &sendctrlp, 0, sizeof ( sendctrlp ) );
- BIT_FILL_1 ( &sendctrlp, SendEnable, 1 );
- qib7322_writeq ( qib7322, &sendctrlp, QIB_7322_SendCtrl_0_offset );
- qib7322_writeq ( qib7322, &sendctrlp, QIB_7322_SendCtrl_1_offset );
-
-
- memset ( &sendctrl, 0, sizeof ( sendctrl ) );
- BIT_FILL_1 ( &sendctrl, SendBufAvailUpd, 1 );
- qib7322_writeq ( qib7322, &sendctrl, QIB_7322_SendCtrl_offset );
-
- return 0;
-
- free_dma ( qib7322->sendbufavail, sizeof ( *qib7322->sendbufavail ) );
- err_alloc_sendbufavail:
- qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_vl15_port1 );
- err_create_send_bufs_vl15_port1:
- qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_vl15_port0 );
- err_create_send_bufs_vl15_port0:
- qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_small );
- err_create_send_bufs_small:
- return rc;
- }
-
-
- static void qib7322_fini_send ( struct qib7322 *qib7322 ) {
- struct QIB_7322_SendCtrl sendctrl;
-
-
- memset ( &sendctrl, 0, sizeof ( sendctrl ) );
- qib7322_writeq ( qib7322, &sendctrl, QIB_7322_SendCtrl_offset );
- mb();
-
-
- qib7322_readq ( qib7322, &sendctrl, QIB_7322_SendCtrl_offset );
-
- free_dma ( qib7322->sendbufavail, sizeof ( *qib7322->sendbufavail ) );
- qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_vl15_port1 );
- qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_vl15_port0 );
- qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_small );
- }
-
-
-
-
- static int qib7322_create_recv_wq ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->recv;
- struct qib7322_recv_work_queue *qib7322_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7322_RcvHdrAddr0 rcvhdraddr;
- struct QIB_7322_RcvHdrTailAddr0 rcvhdrtailaddr;
- struct QIB_7322_RcvHdrHead0 rcvhdrhead;
- struct QIB_7322_scalar rcvegrindexhead;
- struct QIB_7322_RcvCtrl rcvctrl;
- struct QIB_7322_RcvCtrl_P rcvctrlp;
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
- unsigned int ctx = qib7322_ctx ( ibdev, qp );
- int rc;
-
-
- memset ( &qib7322_wq->header_prod, 0,
- sizeof ( qib7322_wq->header_prod ) );
- qib7322_wq->header_cons = 0;
- qib7322_wq->eager_prod = 0;
- qib7322_wq->eager_cons = 0;
-
-
- qib7322_wq->header = malloc_dma ( QIB7322_RECV_HEADERS_SIZE,
- QIB7322_RECV_HEADERS_ALIGN );
- if ( ! qib7322_wq->header ) {
- rc = -ENOMEM;
- goto err_alloc_header;
- }
-
-
- memset ( &rcvhdraddr, 0, sizeof ( rcvhdraddr ) );
- BIT_FILL_1 ( &rcvhdraddr, RcvHdrAddr,
- ( virt_to_bus ( qib7322_wq->header ) >> 2 ) );
- qib7322_writeq_array8b ( qib7322, &rcvhdraddr,
- QIB_7322_RcvHdrAddr0_offset, ctx );
- memset ( &rcvhdrtailaddr, 0, sizeof ( rcvhdrtailaddr ) );
- BIT_FILL_1 ( &rcvhdrtailaddr, RcvHdrTailAddr,
- ( virt_to_bus ( &qib7322_wq->header_prod ) >> 2 ) );
- qib7322_writeq_array8b ( qib7322, &rcvhdrtailaddr,
- QIB_7322_RcvHdrTailAddr0_offset, ctx );
- memset ( &rcvhdrhead, 0, sizeof ( rcvhdrhead ) );
- BIT_FILL_1 ( &rcvhdrhead, counter, 1 );
- qib7322_writeq_array64k ( qib7322, &rcvhdrhead,
- QIB_7322_RcvHdrHead0_offset, ctx );
- memset ( &rcvegrindexhead, 0, sizeof ( rcvegrindexhead ) );
- BIT_FILL_1 ( &rcvegrindexhead, Value, 1 );
- qib7322_writeq_array64k ( qib7322, &rcvegrindexhead,
- QIB_7322_RcvEgrIndexHead0_offset, ctx );
- qib7322_readq_port ( qib7322, &rcvctrlp,
- QIB_7322_RcvCtrl_0_offset, port );
- BIT_SET ( &rcvctrlp, ContextEnable[ctx], 1 );
- qib7322_writeq_port ( qib7322, &rcvctrlp,
- QIB_7322_RcvCtrl_0_offset, port );
- qib7322_readq ( qib7322, &rcvctrl, QIB_7322_RcvCtrl_offset );
- BIT_SET ( &rcvctrl, IntrAvail[ctx], 1 );
- qib7322_writeq ( qib7322, &rcvctrl, QIB_7322_RcvCtrl_offset );
-
- DBGC ( qib7322, "QIB7322 %p port %d QPN %ld CTX %d hdrs [%lx,%lx) prod "
- "%lx\n", qib7322, port, qp->qpn, ctx,
- virt_to_bus ( qib7322_wq->header ),
- ( virt_to_bus ( qib7322_wq->header )
- + QIB7322_RECV_HEADERS_SIZE ),
- virt_to_bus ( &qib7322_wq->header_prod ) );
- return 0;
-
- free_dma ( qib7322_wq->header, QIB7322_RECV_HEADERS_SIZE );
- err_alloc_header:
- return rc;
- }
-
-
- static void qib7322_destroy_recv_wq ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->recv;
- struct qib7322_recv_work_queue *qib7322_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7322_RcvCtrl rcvctrl;
- struct QIB_7322_RcvCtrl_P rcvctrlp;
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
- unsigned int ctx = qib7322_ctx ( ibdev, qp );
-
-
- qib7322_readq_port ( qib7322, &rcvctrlp,
- QIB_7322_RcvCtrl_0_offset, port );
- BIT_SET ( &rcvctrlp, ContextEnable[ctx], 0 );
- qib7322_writeq_port ( qib7322, &rcvctrlp,
- QIB_7322_RcvCtrl_0_offset, port );
- qib7322_readq ( qib7322, &rcvctrl, QIB_7322_RcvCtrl_offset );
- BIT_SET ( &rcvctrl, IntrAvail[ctx], 0 );
- qib7322_writeq ( qib7322, &rcvctrl, QIB_7322_RcvCtrl_offset );
-
-
- qib7322_readq ( qib7322, &rcvctrl, QIB_7322_RcvCtrl_offset );
- mb();
-
-
- free_dma ( qib7322_wq->header, QIB7322_RECV_HEADERS_SIZE );
- }
-
-
- static int qib7322_init_recv ( struct qib7322 *qib7322 ) {
- struct QIB_7322_RcvCtrl rcvctrl;
- struct QIB_7322_RcvCtrl_0 rcvctrlp;
- struct QIB_7322_RcvQPMapTableA_0 rcvqpmaptablea0;
- struct QIB_7322_RcvQPMapTableB_0 rcvqpmaptableb0;
- struct QIB_7322_RcvQPMapTableA_1 rcvqpmaptablea1;
- struct QIB_7322_RcvQPMapTableB_1 rcvqpmaptableb1;
- struct QIB_7322_RcvQPMulticastContext_0 rcvqpmcastctx0;
- struct QIB_7322_RcvQPMulticastContext_1 rcvqpmcastctx1;
- struct QIB_7322_scalar rcvegrbase;
- struct QIB_7322_scalar rcvhdrentsize;
- struct QIB_7322_scalar rcvhdrcnt;
- struct QIB_7322_RcvBTHQP_0 rcvbthqp;
- struct QIB_7322_RxCreditVL0_0 rxcreditvl;
- unsigned int contextcfg;
- unsigned long egrbase;
- unsigned int eager_array_size_kernel;
- unsigned int eager_array_size_user;
- unsigned int user_context_mask;
- unsigned int ctx;
-
-
- switch ( QIB7322_NUM_CONTEXTS ) {
- case 6:
- contextcfg = QIB7322_CONTEXTCFG_6CTX;
- eager_array_size_kernel = QIB7322_EAGER_ARRAY_SIZE_6CTX_KERNEL;
- eager_array_size_user = QIB7322_EAGER_ARRAY_SIZE_6CTX_USER;
- user_context_mask = 0x000f;
- break;
- case 10:
- contextcfg = QIB7322_CONTEXTCFG_10CTX;
- eager_array_size_kernel = QIB7322_EAGER_ARRAY_SIZE_10CTX_KERNEL;
- eager_array_size_user = QIB7322_EAGER_ARRAY_SIZE_10CTX_USER;
- user_context_mask = 0x00ff;
- break;
- case 18:
- contextcfg = QIB7322_CONTEXTCFG_18CTX;
- eager_array_size_kernel = QIB7322_EAGER_ARRAY_SIZE_18CTX_KERNEL;
- eager_array_size_user = QIB7322_EAGER_ARRAY_SIZE_18CTX_USER;
- user_context_mask = 0xffff;
- break;
- default:
- linker_assert ( 0, invalid_QIB7322_NUM_CONTEXTS );
- return -EINVAL;
- }
-
-
- memset ( &rcvctrl, 0, sizeof ( rcvctrl ) );
- BIT_FILL_2 ( &rcvctrl,
- TailUpd, 1,
- ContextCfg, contextcfg );
- qib7322_writeq ( qib7322, &rcvctrl, QIB_7322_RcvCtrl_offset );
-
-
- memset ( &rcvctrlp, 0, sizeof ( rcvctrlp ) );
- BIT_FILL_3 ( &rcvctrlp,
- RcvIBPortEnable, 1,
- RcvQPMapEnable, 1,
- RcvPartitionKeyDisable, 1 );
- qib7322_writeq ( qib7322, &rcvctrlp, QIB_7322_RcvCtrl_0_offset );
- qib7322_writeq ( qib7322, &rcvctrlp, QIB_7322_RcvCtrl_1_offset );
- memset ( &rcvqpmaptablea0, 0, sizeof ( rcvqpmaptablea0 ) );
- BIT_FILL_6 ( &rcvqpmaptablea0,
- RcvQPMapContext0, 0,
- RcvQPMapContext1, 2,
- RcvQPMapContext2, 4,
- RcvQPMapContext3, 6,
- RcvQPMapContext4, 8,
- RcvQPMapContext5, 10 );
- qib7322_writeq ( qib7322, &rcvqpmaptablea0,
- QIB_7322_RcvQPMapTableA_0_offset );
- memset ( &rcvqpmaptableb0, 0, sizeof ( rcvqpmaptableb0 ) );
- BIT_FILL_3 ( &rcvqpmaptableb0,
- RcvQPMapContext6, 12,
- RcvQPMapContext7, 14,
- RcvQPMapContext8, 16 );
- qib7322_writeq ( qib7322, &rcvqpmaptableb0,
- QIB_7322_RcvQPMapTableB_0_offset );
- memset ( &rcvqpmaptablea1, 0, sizeof ( rcvqpmaptablea1 ) );
- BIT_FILL_6 ( &rcvqpmaptablea1,
- RcvQPMapContext0, 1,
- RcvQPMapContext1, 3,
- RcvQPMapContext2, 5,
- RcvQPMapContext3, 7,
- RcvQPMapContext4, 9,
- RcvQPMapContext5, 11 );
- qib7322_writeq ( qib7322, &rcvqpmaptablea1,
- QIB_7322_RcvQPMapTableA_1_offset );
- memset ( &rcvqpmaptableb1, 0, sizeof ( rcvqpmaptableb1 ) );
- BIT_FILL_3 ( &rcvqpmaptableb1,
- RcvQPMapContext6, 13,
- RcvQPMapContext7, 15,
- RcvQPMapContext8, 17 );
- qib7322_writeq ( qib7322, &rcvqpmaptableb1,
- QIB_7322_RcvQPMapTableB_1_offset );
-
-
- memset ( &rcvqpmcastctx0, 0, sizeof ( rcvqpmcastctx0 ) );
- BIT_FILL_1 ( &rcvqpmcastctx0, RcvQpMcContext, 0 );
- qib7322_writeq ( qib7322, &rcvqpmcastctx0,
- QIB_7322_RcvQPMulticastContext_0_offset );
- memset ( &rcvqpmcastctx1, 0, sizeof ( rcvqpmcastctx1 ) );
- BIT_FILL_1 ( &rcvqpmcastctx1, RcvQpMcContext, 1 );
- qib7322_writeq ( qib7322, &rcvqpmcastctx1,
- QIB_7322_RcvQPMulticastContext_1_offset );
-
-
- memset ( &rcvhdrcnt, 0, sizeof ( rcvhdrcnt ) );
- BIT_FILL_1 ( &rcvhdrcnt, Value, QIB7322_RECV_HEADER_COUNT );
- qib7322_writeq ( qib7322, &rcvhdrcnt, QIB_7322_RcvHdrCnt_offset );
- memset ( &rcvhdrentsize, 0, sizeof ( rcvhdrentsize ) );
- BIT_FILL_1 ( &rcvhdrentsize, Value, ( QIB7322_RECV_HEADER_SIZE >> 2 ) );
- qib7322_writeq ( qib7322, &rcvhdrentsize,
- QIB_7322_RcvHdrEntSize_offset );
-
-
- qib7322_readq ( qib7322, &rcvegrbase, QIB_7322_RcvEgrBase_offset );
- egrbase = BIT_GET ( &rcvegrbase, Value );
- for ( ctx = 0 ; ctx < QIB7322_MAX_PORTS ; ctx++ ) {
- qib7322->recv_wq[ctx].eager_array = egrbase;
- qib7322->recv_wq[ctx].eager_entries = eager_array_size_kernel;
- egrbase += ( eager_array_size_kernel *
- sizeof ( struct QIB_7322_RcvEgr ) );
- }
- for ( ; ctx < QIB7322_NUM_CONTEXTS ; ctx++ ) {
- qib7322->recv_wq[ctx].eager_array = egrbase;
- qib7322->recv_wq[ctx].eager_entries = eager_array_size_user;
- egrbase += ( eager_array_size_user *
- sizeof ( struct QIB_7322_RcvEgr ) );
- }
- for ( ctx = 0 ; ctx < QIB7322_NUM_CONTEXTS ; ctx++ ) {
- DBGC ( qib7322, "QIB7322 %p CTX %d eager array at %lx (%d "
- "entries)\n", qib7322, ctx,
- qib7322->recv_wq[ctx].eager_array,
- qib7322->recv_wq[ctx].eager_entries );
- }
-
-
- memset ( &rcvbthqp, 0, sizeof ( rcvbthqp ) );
- BIT_FILL_1 ( &rcvbthqp, RcvBTHQP, QIB7322_QP_IDETH );
- qib7322_writeq ( qib7322, &rcvbthqp, QIB_7322_RcvBTHQP_0_offset );
- qib7322_writeq ( qib7322, &rcvbthqp, QIB_7322_RcvBTHQP_1_offset );
-
-
- memset ( &rxcreditvl, 0, sizeof ( rxcreditvl ) );
- BIT_FILL_1 ( &rxcreditvl, RxMaxCreditVL, QIB7322_MAX_CREDITS_VL0 );
- qib7322_writeq_array8b ( qib7322, &rxcreditvl,
- QIB_7322_RxCreditVL0_0_offset, 0 );
- qib7322_writeq_array8b ( qib7322, &rxcreditvl,
- QIB_7322_RxCreditVL0_1_offset, 0 );
- BIT_FILL_1 ( &rxcreditvl, RxMaxCreditVL, QIB7322_MAX_CREDITS_VL15 );
- qib7322_writeq_array8b ( qib7322, &rxcreditvl,
- QIB_7322_RxCreditVL0_0_offset, 15 );
- qib7322_writeq_array8b ( qib7322, &rxcreditvl,
- QIB_7322_RxCreditVL0_1_offset, 15 );
-
- return 0;
- }
-
-
- static void qib7322_fini_recv ( struct qib7322 *qib7322 __unused ) {
-
-
- }
-
-
-
-
- static int qib7322_create_cq ( struct ib_device *ibdev,
- struct ib_completion_queue *cq ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- static int cqn;
-
-
-
- cq->cqn = ++cqn;
- DBGC ( qib7322, "QIB7322 %p CQN %ld created\n", qib7322, cq->cqn );
-
- return 0;
- }
-
-
- static void qib7322_destroy_cq ( struct ib_device *ibdev,
- struct ib_completion_queue *cq ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
-
-
- DBGC ( qib7322, "QIB7322 %p CQN %ld destroyed\n", qib7322, cq->cqn );
- }
-
-
-
-
- static int qib7322_create_qp ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- unsigned int ctx;
- int rc;
-
-
- if ( ( rc = qib7322_alloc_ctx ( ibdev, qp ) ) != 0 )
- goto err_alloc_ctx;
- ctx = qib7322_ctx ( ibdev, qp );
-
-
- ib_wq_set_drvdata ( &qp->send, &qib7322->send_wq[ctx] );
- ib_wq_set_drvdata ( &qp->recv, &qib7322->recv_wq[ctx] );
-
-
- if ( ( rc = qib7322_create_recv_wq ( ibdev, qp ) ) != 0 )
- goto err_create_recv_wq;
-
-
- if ( ( rc = qib7322_create_send_wq ( ibdev, qp ) ) != 0 )
- goto err_create_send_wq;
-
- return 0;
-
- qib7322_destroy_send_wq ( ibdev, qp );
- err_create_send_wq:
- qib7322_destroy_recv_wq ( ibdev, qp );
- err_create_recv_wq:
- qib7322_free_ctx ( ibdev, qp );
- err_alloc_ctx:
- return rc;
- }
-
-
- static int qib7322_modify_qp ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
-
-
-
- DBGC2 ( qib7322, "QIB7322 %p QPN %ld modified\n", qib7322, qp->qpn );
- return 0;
- }
-
-
- static void qib7322_destroy_qp ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
-
- qib7322_destroy_send_wq ( ibdev, qp );
- qib7322_destroy_recv_wq ( ibdev, qp );
- qib7322_free_ctx ( ibdev, qp );
- }
-
-
-
-
- static int qib7322_post_send ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- struct ib_address_vector *av,
- struct io_buffer *iobuf ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->send;
- struct qib7322_send_work_queue *qib7322_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7322_SendPbc sendpbc;
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
- uint8_t header_buf[IB_MAX_HEADER_SIZE];
- struct io_buffer headers;
- int send_buf;
- unsigned long start_offset;
- unsigned long offset;
- size_t len;
- ssize_t frag_len;
- uint32_t *data;
-
-
- send_buf = qib7322_alloc_send_buf ( qib7322, qib7322_wq->send_bufs );
- if ( send_buf < 0 )
- return send_buf;
- start_offset = offset =
- qib7322_send_buffer_offset ( qib7322, qib7322_wq->send_bufs,
- send_buf );
-
-
- assert ( wq->iobufs[qib7322_wq->prod] == NULL );
- wq->iobufs[qib7322_wq->prod] = iobuf;
- qib7322_wq->used[qib7322_wq->prod] = send_buf;
-
-
- iob_populate ( &headers, header_buf, 0, sizeof ( header_buf ) );
- iob_reserve ( &headers, sizeof ( header_buf ) );
- ib_push ( ibdev, &headers, qp, iob_len ( iobuf ), av );
-
-
- len = ( ( sizeof ( sendpbc ) + iob_len ( &headers ) +
- iob_len ( iobuf ) + 3 ) & ~3 );
-
-
- memset ( &sendpbc, 0, sizeof ( sendpbc ) );
- BIT_FILL_3 ( &sendpbc,
- LengthP1_toibc, ( ( len >> 2 ) - 1 ),
- Port, port,
- VL15, ( ( qp->type == IB_QPT_SMI ) ? 1 : 0 ) );
-
-
- DBG_DISABLE ( DBGLVL_IO );
- qib7322_writeq ( qib7322, &sendpbc, offset );
- offset += sizeof ( sendpbc );
-
-
- for ( data = headers.data, frag_len = iob_len ( &headers ) ;
- frag_len > 0 ; data++, offset += 4, frag_len -= 4 ) {
- qib7322_writel ( qib7322, *data, offset );
- }
-
-
- for ( data = iobuf->data, frag_len = iob_len ( iobuf ) ;
- frag_len > 0 ; data++, offset += 4, frag_len -= 4 ) {
- qib7322_writel ( qib7322, *data, offset );
- }
- DBG_ENABLE ( DBGLVL_IO );
-
- assert ( ( start_offset + len ) == offset );
- DBGC2 ( qib7322, "QIB7322 %p QPN %ld TX %04x(%04x) posted [%lx,%lx)\n",
- qib7322, qp->qpn, send_buf, qib7322_wq->prod,
- start_offset, offset );
-
-
- qib7322_wq->prod = ( ( qib7322_wq->prod + 1 ) & ( wq->num_wqes - 1 ) );
-
- return 0;
- }
-
-
- static void qib7322_complete_send ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- unsigned int wqe_idx ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->send;
- struct qib7322_send_work_queue *qib7322_wq = ib_wq_get_drvdata ( wq );
- struct io_buffer *iobuf;
- unsigned int send_buf;
-
-
- send_buf = qib7322_wq->used[wqe_idx];
- DBGC2 ( qib7322, "QIB7322 %p QPN %ld TX %04x(%04x) complete\n",
- qib7322, qp->qpn, send_buf, wqe_idx );
-
-
- iobuf = wq->iobufs[wqe_idx];
- assert ( iobuf != NULL );
- ib_complete_send ( ibdev, qp, iobuf, 0 );
- wq->iobufs[wqe_idx] = NULL;
-
-
- qib7322_free_send_buf ( qib7322, qib7322_wq->send_bufs, send_buf );
- }
-
-
- static void qib7322_poll_send_wq ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->send;
- struct qib7322_send_work_queue *qib7322_wq = ib_wq_get_drvdata ( wq );
- unsigned int send_buf;
-
-
- while ( wq->fill ) {
-
-
- send_buf = qib7322_wq->used[qib7322_wq->cons];
- if ( qib7322_send_buf_in_use ( qib7322, send_buf ) )
- break;
-
-
- qib7322_complete_send ( ibdev, qp, qib7322_wq->cons );
-
-
- qib7322_wq->cons = ( ( qib7322_wq->cons + 1 ) &
- ( wq->num_wqes - 1 ) );
- }
- }
-
-
- static int qib7322_post_recv ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- struct io_buffer *iobuf ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->recv;
- struct qib7322_recv_work_queue *qib7322_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7322_RcvEgr rcvegr;
- struct QIB_7322_scalar rcvegrindexhead;
- unsigned int ctx = qib7322_ctx ( ibdev, qp );
- physaddr_t addr;
- size_t len;
- unsigned int wqe_idx;
- unsigned int bufsize;
-
-
- addr = virt_to_bus ( iobuf->data );
- len = iob_tailroom ( iobuf );
- if ( addr & ( QIB7322_EAGER_BUFFER_ALIGN - 1 ) ) {
- DBGC ( qib7322, "QIB7322 %p QPN %ld misaligned RX buffer "
- "(%08lx)\n", qib7322, qp->qpn, addr );
- return -EINVAL;
- }
- if ( len != QIB7322_RECV_PAYLOAD_SIZE ) {
- DBGC ( qib7322, "QIB7322 %p QPN %ld wrong RX buffer size "
- "(%zd)\n", qib7322, qp->qpn, len );
- return -EINVAL;
- }
-
-
- wqe_idx = ( qib7322_wq->eager_prod & ( wq->num_wqes - 1 ) );
- assert ( wq->iobufs[wqe_idx] == NULL );
-
-
- wq->iobufs[wqe_idx] = iobuf;
-
-
- switch ( QIB7322_RECV_PAYLOAD_SIZE ) {
- case 2048: bufsize = QIB7322_EAGER_BUFFER_2K; break;
- case 4096: bufsize = QIB7322_EAGER_BUFFER_4K; break;
- case 8192: bufsize = QIB7322_EAGER_BUFFER_8K; break;
- case 16384: bufsize = QIB7322_EAGER_BUFFER_16K; break;
- case 32768: bufsize = QIB7322_EAGER_BUFFER_32K; break;
- case 65536: bufsize = QIB7322_EAGER_BUFFER_64K; break;
- default: linker_assert ( 0, invalid_rx_payload_size );
- bufsize = QIB7322_EAGER_BUFFER_NONE;
- }
-
-
- memset ( &rcvegr, 0, sizeof ( rcvegr ) );
- BIT_FILL_2 ( &rcvegr,
- Addr, ( addr >> 11 ),
- BufSize, bufsize );
- qib7322_writeq_array8b ( qib7322, &rcvegr, qib7322_wq->eager_array,
- qib7322_wq->eager_prod );
- DBGC2 ( qib7322, "QIB7322 %p QPN %ld RX egr %04x(%04x) posted "
- "[%lx,%lx)\n", qib7322, qp->qpn, qib7322_wq->eager_prod,
- wqe_idx, addr, ( addr + len ) );
-
-
- qib7322_wq->eager_prod = ( ( qib7322_wq->eager_prod + 1 ) &
- ( qib7322_wq->eager_entries - 1 ) );
-
-
- memset ( &rcvegrindexhead, 0, sizeof ( rcvegrindexhead ) );
- BIT_FILL_1 ( &rcvegrindexhead,
- Value, ( ( qib7322_wq->eager_prod + 1 ) &
- ( qib7322_wq->eager_entries - 1 ) ) );
- qib7322_writeq_array64k ( qib7322, &rcvegrindexhead,
- QIB_7322_RcvEgrIndexHead0_offset, ctx );
-
- return 0;
- }
-
-
- static void qib7322_complete_recv ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- unsigned int header_offs ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->recv;
- struct qib7322_recv_work_queue *qib7322_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7322_RcvHdrFlags *rcvhdrflags;
- struct QIB_7322_RcvEgr rcvegr;
- struct io_buffer headers;
- struct io_buffer *iobuf;
- struct ib_queue_pair *intended_qp;
- struct ib_address_vector av;
- unsigned int rcvtype;
- unsigned int pktlen;
- unsigned int egrindex;
- unsigned int useegrbfr;
- unsigned int iberr, mkerr, tiderr, khdrerr, mtuerr;
- unsigned int lenerr, parityerr, vcrcerr, icrcerr;
- unsigned int err;
- unsigned int hdrqoffset;
- unsigned int header_len;
- unsigned int padded_payload_len;
- unsigned int wqe_idx;
- size_t payload_len;
- int qp0;
- int rc;
-
-
- rcvhdrflags = ( qib7322_wq->header + header_offs +
- QIB7322_RECV_HEADER_SIZE - sizeof ( *rcvhdrflags ) );
- rcvtype = BIT_GET ( rcvhdrflags, RcvType );
- pktlen = ( BIT_GET ( rcvhdrflags, PktLen ) << 2 );
- egrindex = BIT_GET ( rcvhdrflags, EgrIndex );
- useegrbfr = BIT_GET ( rcvhdrflags, UseEgrBfr );
- hdrqoffset = ( BIT_GET ( rcvhdrflags, HdrqOffset ) << 2 );
- iberr = BIT_GET ( rcvhdrflags, IBErr );
- mkerr = BIT_GET ( rcvhdrflags, MKErr );
- tiderr = BIT_GET ( rcvhdrflags, TIDErr );
- khdrerr = BIT_GET ( rcvhdrflags, KHdrErr );
- mtuerr = BIT_GET ( rcvhdrflags, MTUErr );
- lenerr = BIT_GET ( rcvhdrflags, LenErr );
- parityerr = BIT_GET ( rcvhdrflags, ParityErr );
- vcrcerr = BIT_GET ( rcvhdrflags, VCRCErr );
- icrcerr = BIT_GET ( rcvhdrflags, ICRCErr );
- header_len = ( QIB7322_RECV_HEADER_SIZE - hdrqoffset -
- sizeof ( *rcvhdrflags ) );
- padded_payload_len = ( pktlen - header_len - 4 );
- err = ( iberr | mkerr | tiderr | khdrerr | mtuerr |
- lenerr | parityerr | vcrcerr | icrcerr );
-
- iob_populate ( &headers, ( ( ( void * ) rcvhdrflags ) - header_len ),
- header_len, header_len );
-
-
- DBGC2 ( qib7322, "QIB7322 %p QPN %ld RX egr %04x%s hdr %d type %d len "
- "%d(%d+%d+4)%s%s%s%s%s%s%s%s%s%s%s\n", qib7322, qp->qpn,
- egrindex, ( useegrbfr ? "" : "(unused)" ),
- ( header_offs / QIB7322_RECV_HEADER_SIZE ),
- rcvtype, pktlen, header_len, padded_payload_len,
- ( err ? " [Err" : "" ), ( iberr ? " IB" : "" ),
- ( mkerr ? " MK" : "" ), ( tiderr ? " TID" : "" ),
- ( khdrerr ? " KHdr" : "" ), ( mtuerr ? " MTU" : "" ),
- ( lenerr ? " Len" : "" ), ( parityerr ? " Parity" : ""),
- ( vcrcerr ? " VCRC" : "" ), ( icrcerr ? " ICRC" : "" ),
- ( err ? "]" : "" ) );
- DBGCP_HDA ( qib7322, hdrqoffset, headers.data,
- ( header_len + sizeof ( *rcvhdrflags ) ) );
-
-
- qp0 = ( qp->qpn == 0 );
- intended_qp = NULL;
- if ( ( rc = ib_pull ( ibdev, &headers, ( qp0 ? &intended_qp : NULL ),
- &payload_len, &av ) ) != 0 ) {
- DBGC ( qib7322, "QIB7322 %p could not parse headers: %s\n",
- qib7322, strerror ( rc ) );
- err = 1;
- }
- if ( ! intended_qp )
- intended_qp = qp;
-
-
-
- while ( 1 ) {
-
-
-
- if ( qib7322_wq->eager_cons == qib7322_wq->eager_prod )
- break;
-
-
-
- if ( ( qib7322_wq->eager_cons ==
- ( ( egrindex + 1 ) & ( qib7322_wq->eager_entries - 1 ))))
- break;
-
-
-
- wqe_idx = ( qib7322_wq->eager_cons & ( wq->num_wqes - 1 ) );
- iobuf = wq->iobufs[wqe_idx];
- assert ( iobuf != NULL );
- wq->iobufs[wqe_idx] = NULL;
-
-
- if ( qib7322_wq->eager_cons == egrindex ) {
-
-
- iob_put ( iobuf, payload_len );
- rc = ( err ? -EIO : ( useegrbfr ? 0 : -ECANCELED ) );
-
- if ( qp != intended_qp ) {
- DBGC2 ( qib7322, "QIB7322 %p redirecting QPN "
- "%ld => %ld\n",
- qib7322, qp->qpn, intended_qp->qpn );
-
- qp->recv.fill--;
- intended_qp->recv.fill++;
- }
- ib_complete_recv ( ibdev, intended_qp, &av, iobuf, rc);
- } else {
-
- ib_complete_recv ( ibdev, qp, &av, iobuf, -ECANCELED );
- }
-
-
- memset ( &rcvegr, 0, sizeof ( rcvegr ) );
- qib7322_writeq_array8b ( qib7322, &rcvegr,
- qib7322_wq->eager_array,
- qib7322_wq->eager_cons );
-
-
- qib7322_wq->eager_cons = ( ( qib7322_wq->eager_cons + 1 ) &
- ( qib7322_wq->eager_entries - 1 ) );
- }
- }
-
-
- static void qib7322_poll_recv_wq ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->recv;
- struct qib7322_recv_work_queue *qib7322_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7322_RcvHdrHead0 rcvhdrhead;
- unsigned int ctx = qib7322_ctx ( ibdev, qp );
- unsigned int header_prod;
-
-
- header_prod = ( BIT_GET ( &qib7322_wq->header_prod, Value ) << 2 );
- if ( header_prod == qib7322_wq->header_cons )
- return;
-
-
- while ( qib7322_wq->header_cons != header_prod ) {
-
-
- qib7322_complete_recv ( ibdev, qp, qib7322_wq->header_cons );
-
-
- qib7322_wq->header_cons += QIB7322_RECV_HEADER_SIZE;
- qib7322_wq->header_cons %= QIB7322_RECV_HEADERS_SIZE;
-
-
-
- if ( qp->type == IB_QPT_SMI )
- break;
- }
-
-
- memset ( &rcvhdrhead, 0, sizeof ( rcvhdrhead ) );
- BIT_FILL_2 ( &rcvhdrhead,
- RcvHeadPointer, ( qib7322_wq->header_cons >> 2 ),
- counter, 1 );
- qib7322_writeq_array64k ( qib7322, &rcvhdrhead,
- QIB_7322_RcvHdrHead0_offset, ctx );
- }
-
-
- static void qib7322_poll_cq ( struct ib_device *ibdev,
- struct ib_completion_queue *cq ) {
- struct ib_work_queue *wq;
-
-
- list_for_each_entry ( wq, &cq->work_queues, list ) {
- if ( wq->is_send ) {
- qib7322_poll_send_wq ( ibdev, wq->qp );
- } else {
- qib7322_poll_recv_wq ( ibdev, wq->qp );
- }
- }
- }
-
-
-
-
- static void qib7322_poll_eq ( struct ib_device *ibdev ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct QIB_7322_ErrStatus_0 errstatus;
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
-
-
- DBG_DISABLE ( DBGLVL_IO );
- qib7322_readq_port ( qib7322, &errstatus,
- QIB_7322_ErrStatus_0_offset, port );
- if ( errstatus.u.qwords[0] ) {
- DBGC ( qib7322, "QIB7322 %p port %d status %08x%08x\n", qib7322,
- port, errstatus.u.dwords[1], errstatus.u.dwords[0] );
- qib7322_writeq_port ( qib7322, &errstatus,
- QIB_7322_ErrClear_0_offset, port );
- }
- DBG_ENABLE ( DBGLVL_IO );
-
-
- if ( BIT_GET ( &errstatus, IBStatusChanged ) )
- qib7322_link_state_changed ( ibdev );
- }
-
-
-
-
- static unsigned int qib7322_link_speed_supported ( struct qib7322 *qib7322,
- unsigned int port ) {
- struct QIB_7322_feature_mask features;
- struct QIB_7322_Revision revision;
- unsigned int supported;
- unsigned int boardid;
-
-
- qib7322_readq ( qib7322, &features,
- QIB_7322_active_feature_mask_offset );
- switch ( port ) {
- case 0 :
- supported = BIT_GET ( &features, Port0_Link_Speed_Supported );
- break;
- case 1 :
- supported = BIT_GET ( &features, Port1_Link_Speed_Supported );
- break;
- default:
- DBGC ( qib7322, "QIB7322 %p port %d is invalid\n",
- qib7322, port );
- supported = 0;
- break;
- }
-
-
- qib7322_readq ( qib7322, &revision, QIB_7322_Revision_offset );
- boardid = BIT_GET ( &revision, BoardID );
- switch ( boardid ) {
- case QIB7322_BOARD_QMH7342 :
- DBGC2 ( qib7322, "QIB7322 %p is a QMH7342; forcing QDR-only\n",
- qib7322 );
- supported = IB_LINK_SPEED_QDR;
- break;
- default:
-
- break;
- }
-
- DBGC2 ( qib7322, "QIB7322 %p port %d %s%s%s%s\n", qib7322, port,
- ( supported ? "supports" : "disabled" ),
- ( ( supported & IB_LINK_SPEED_SDR ) ? " SDR" : "" ),
- ( ( supported & IB_LINK_SPEED_DDR ) ? " DDR" : "" ),
- ( ( supported & IB_LINK_SPEED_QDR ) ? " QDR" : "" ) );
- return supported;
- }
-
-
- static int qib7322_open ( struct ib_device *ibdev ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct QIB_7322_IBCCtrlA_0 ibcctrla;
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
-
-
- qib7322_readq_port ( qib7322, &ibcctrla,
- QIB_7322_IBCCtrlA_0_offset, port );
- BIT_SET ( &ibcctrla, IBLinkEn, 1 );
- qib7322_writeq_port ( qib7322, &ibcctrla,
- QIB_7322_IBCCtrlA_0_offset, port );
-
- return 0;
- }
-
-
- static void qib7322_close ( struct ib_device *ibdev ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
- struct QIB_7322_IBCCtrlA_0 ibcctrla;
- unsigned int port = ( ibdev->port - QIB7322_PORT_BASE );
-
-
- qib7322_readq_port ( qib7322, &ibcctrla,
- QIB_7322_IBCCtrlA_0_offset, port );
- BIT_SET ( &ibcctrla, IBLinkEn, 0 );
- qib7322_writeq_port ( qib7322, &ibcctrla,
- QIB_7322_IBCCtrlA_0_offset, port );
- }
-
-
-
-
- static int qib7322_mcast_attach ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- struct ib_gid *gid ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
-
- ( void ) qib7322;
- ( void ) qp;
- ( void ) gid;
- return 0;
- }
-
-
- static void qib7322_mcast_detach ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- struct ib_gid *gid ) {
- struct qib7322 *qib7322 = ib_get_drvdata ( ibdev );
-
- ( void ) qib7322;
- ( void ) qp;
- ( void ) gid;
- }
-
-
- static struct ib_device_operations qib7322_ib_operations = {
- .create_cq = qib7322_create_cq,
- .destroy_cq = qib7322_destroy_cq,
- .create_qp = qib7322_create_qp,
- .modify_qp = qib7322_modify_qp,
- .destroy_qp = qib7322_destroy_qp,
- .post_send = qib7322_post_send,
- .post_recv = qib7322_post_recv,
- .poll_cq = qib7322_poll_cq,
- .poll_eq = qib7322_poll_eq,
- .open = qib7322_open,
- .close = qib7322_close,
- .mcast_attach = qib7322_mcast_attach,
- .mcast_detach = qib7322_mcast_detach,
- .set_port_info = qib7322_set_port_info,
- .set_pkey_table = qib7322_set_pkey_table,
- };
-
-
-
-
- static unsigned int qib7322_i2c_bits[] = {
- [I2C_BIT_SCL] = ( 1 << QIB7322_GPIO_SCL ),
- [I2C_BIT_SDA] = ( 1 << QIB7322_GPIO_SDA ),
- };
-
-
- static int qib7322_i2c_read_bit ( struct bit_basher *basher,
- unsigned int bit_id ) {
- struct qib7322 *qib7322 =
- container_of ( basher, struct qib7322, i2c.basher );
- struct QIB_7322_EXTStatus extstatus;
- unsigned int status;
-
- DBG_DISABLE ( DBGLVL_IO );
-
- qib7322_readq ( qib7322, &extstatus, QIB_7322_EXTStatus_offset );
- status = ( BIT_GET ( &extstatus, GPIOIn ) & qib7322_i2c_bits[bit_id] );
-
- DBG_ENABLE ( DBGLVL_IO );
-
- return status;
- }
-
-
- static void qib7322_i2c_write_bit ( struct bit_basher *basher,
- unsigned int bit_id, unsigned long data ) {
- struct qib7322 *qib7322 =
- container_of ( basher, struct qib7322, i2c.basher );
- struct QIB_7322_EXTCtrl extctrl;
- struct QIB_7322_GPIO gpioout;
- unsigned int bit = qib7322_i2c_bits[bit_id];
- unsigned int outputs = 0;
- unsigned int output_enables = 0;
-
- DBG_DISABLE ( DBGLVL_IO );
-
-
- qib7322_readq ( qib7322, &extctrl, QIB_7322_EXTCtrl_offset );
- qib7322_readq ( qib7322, &gpioout, QIB_7322_GPIOOut_offset );
-
-
-
- output_enables = BIT_GET ( &extctrl, GPIOOe );
- output_enables = ( ( output_enables & ~bit ) | ( ~data & bit ) );
- outputs = BIT_GET ( &gpioout, GPIO );
- outputs = ( outputs & ~bit );
- BIT_SET ( &extctrl, GPIOOe, output_enables );
- BIT_SET ( &gpioout, GPIO, outputs );
-
-
-
- qib7322_writeq ( qib7322, &extctrl, QIB_7322_EXTCtrl_offset );
- qib7322_writeq ( qib7322, &gpioout, QIB_7322_GPIOOut_offset );
- mb();
-
- DBG_ENABLE ( DBGLVL_IO );
- }
-
-
- static struct bit_basher_operations qib7322_i2c_basher_ops = {
- .read = qib7322_i2c_read_bit,
- .write = qib7322_i2c_write_bit,
- };
-
-
- static int qib7322_init_i2c ( struct qib7322 *qib7322 ) {
- static int try_eeprom_address[] = { 0x51, 0x50 };
- unsigned int i;
- int rc;
-
-
- if ( ( rc = init_i2c_bit_basher ( &qib7322->i2c,
- &qib7322_i2c_basher_ops ) ) != 0 ) {
- DBGC ( qib7322, "QIB7322 %p could not initialise I2C bus: %s\n",
- qib7322, strerror ( rc ) );
- return rc;
- }
-
-
- for ( i = 0 ; i < ( sizeof ( try_eeprom_address ) /
- sizeof ( try_eeprom_address[0] ) ) ; i++ ) {
- init_i2c_eeprom ( &qib7322->eeprom, try_eeprom_address[i] );
- if ( ( rc = i2c_check_presence ( &qib7322->i2c.i2c,
- &qib7322->eeprom ) ) == 0 ) {
- DBGC2 ( qib7322, "QIB7322 %p found EEPROM at %02x\n",
- qib7322, try_eeprom_address[i] );
- return 0;
- }
- }
-
- DBGC ( qib7322, "QIB7322 %p could not find EEPROM\n", qib7322 );
- return -ENODEV;
- }
-
-
- static int qib7322_read_eeprom ( struct qib7322 *qib7322 ) {
- struct i2c_interface *i2c = &qib7322->i2c.i2c;
- struct ib_gid_half *guid = &qib7322->guid;
- int rc;
-
-
- if ( ( rc = i2c->read ( i2c, &qib7322->eeprom,
- QIB7322_EEPROM_GUID_OFFSET, guid->u.bytes,
- sizeof ( *guid ) ) ) != 0 ) {
- DBGC ( qib7322, "QIB7322 %p could not read GUID: %s\n",
- qib7322, strerror ( rc ) );
- return rc;
- }
- DBGC2 ( qib7322, "QIB7322 %p has GUID %02x:%02x:%02x:%02x:%02x:%02x:"
- "%02x:%02x\n", qib7322, guid->u.bytes[0], guid->u.bytes[1],
- guid->u.bytes[2], guid->u.bytes[3], guid->u.bytes[4],
- guid->u.bytes[5], guid->u.bytes[6], guid->u.bytes[7] );
-
-
- if ( DBG_LOG ) {
- uint8_t serial[QIB7322_EEPROM_SERIAL_SIZE + 1];
-
- serial[ sizeof ( serial ) - 1 ] = '\0';
- if ( ( rc = i2c->read ( i2c, &qib7322->eeprom,
- QIB7322_EEPROM_SERIAL_OFFSET, serial,
- ( sizeof ( serial ) - 1 ) ) ) != 0 ) {
- DBGC ( qib7322, "QIB7322 %p could not read serial: "
- "%s\n", qib7322, strerror ( rc ) );
- return rc;
- }
- DBGC2 ( qib7322, "QIB7322 %p has serial number \"%s\"\n",
- qib7322, serial );
- }
-
- return 0;
- }
-
-
-
-
- static int qib7322_ahb_wait ( struct qib7322 *qib7322 ) {
- struct QIB_7322_ahb_transaction_reg transaction;
- unsigned int i;
-
-
- for ( i = 0 ; i < QIB7322_AHB_MAX_WAIT_US ; i++ ) {
- qib7322_readq ( qib7322, &transaction,
- QIB_7322_ahb_transaction_reg_offset );
- if ( BIT_GET ( &transaction, ahb_rdy ) )
- return 0;
- udelay ( 1 );
- }
-
- DBGC ( qib7322, "QIB7322 %p timed out waiting for AHB transaction\n",
- qib7322 );
- return -ETIMEDOUT;
- }
-
-
- static int qib7322_ahb_request ( struct qib7322 *qib7322,
- unsigned int location ) {
- struct QIB_7322_ahb_access_ctrl access;
- int rc;
-
-
- memset ( &access, 0, sizeof ( access ) );
- BIT_FILL_2 ( &access,
- sw_ahb_sel, 1,
- sw_sel_ahb_trgt, QIB7322_AHB_LOC_TARGET ( location ) );
- qib7322_writeq ( qib7322, &access, QIB_7322_ahb_access_ctrl_offset );
-
-
- if ( ( rc = qib7322_ahb_wait ( qib7322 ) ) != 0 ) {
- DBGC ( qib7322, "QIB7322 %p could not obtain AHB ownership: "
- "%s\n", qib7322, strerror ( rc ) );
- return rc;
- }
-
- return 0;
- }
-
-
- static void qib7322_ahb_release ( struct qib7322 *qib7322 ) {
- struct QIB_7322_ahb_access_ctrl access;
-
- memset ( &access, 0, sizeof ( access ) );
- qib7322_writeq ( qib7322, &access, QIB_7322_ahb_access_ctrl_offset );
- }
-
-
- static int qib7322_ahb_read ( struct qib7322 *qib7322, unsigned int location,
- uint32_t *data ) {
- struct QIB_7322_ahb_transaction_reg xact;
- int rc;
-
-
- memset ( &xact, 0, sizeof ( xact ) );
- BIT_FILL_2 ( &xact,
- ahb_address, QIB7322_AHB_LOC_ADDRESS ( location ),
- write_not_read, 0 );
- qib7322_writeq ( qib7322, &xact, QIB_7322_ahb_transaction_reg_offset );
-
-
- if ( ( rc = qib7322_ahb_wait ( qib7322 ) ) != 0 )
- return rc;
-
-
- qib7322_readq ( qib7322, &xact, QIB_7322_ahb_transaction_reg_offset );
- *data = BIT_GET ( &xact, ahb_data );
- return 0;
- }
-
-
- static int qib7322_ahb_write ( struct qib7322 *qib7322, unsigned int location,
- uint32_t data ) {
- struct QIB_7322_ahb_transaction_reg xact;
- int rc;
-
-
- memset ( &xact, 0, sizeof ( xact ) );
- BIT_FILL_3 ( &xact,
- ahb_address, QIB7322_AHB_LOC_ADDRESS ( location ),
- write_not_read, 1,
- ahb_data, data );
- qib7322_writeq ( qib7322, &xact, QIB_7322_ahb_transaction_reg_offset );
-
-
- if ( ( rc = qib7322_ahb_wait ( qib7322 ) ) != 0 )
- return rc;
-
- return 0;
- }
-
-
- static int qib7322_ahb_mod_reg ( struct qib7322 *qib7322, unsigned int location,
- uint32_t value, uint32_t mask ) {
- uint32_t old_value;
- uint32_t new_value;
- int rc;
-
- DBG_DISABLE ( DBGLVL_IO );
-
-
- assert ( ( value & mask ) == value );
-
-
- if ( ( rc = qib7322_ahb_request ( qib7322, location ) ) != 0 )
- goto out;
-
-
- if ( ( rc = qib7322_ahb_read ( qib7322, location, &old_value ) ) != 0 )
- goto out_release;
-
-
- new_value = ( ( old_value & ~mask ) | value );
- DBGCP ( qib7322, "QIB7322 %p AHB %x %#08x => %#08x\n",
- qib7322, location, old_value, new_value );
- if ( ( rc = qib7322_ahb_write ( qib7322, location, new_value ) ) != 0 )
- goto out_release;
-
- out_release:
-
- qib7322_ahb_release ( qib7322 );
- out:
- DBG_ENABLE ( DBGLVL_IO );
- return rc;
- }
-
-
- static int qib7322_ahb_mod_reg_all ( struct qib7322 *qib7322, unsigned int reg,
- uint32_t value, uint32_t mask ) {
- unsigned int port;
- unsigned int channel;
- unsigned int location;
- int rc;
-
- for ( port = 0 ; port < QIB7322_MAX_PORTS ; port++ ) {
- for ( channel = 0 ; channel < QIB7322_MAX_WIDTH ; channel++ ) {
- location = QIB7322_AHB_LOCATION ( port, channel, reg );
- if ( ( rc = qib7322_ahb_mod_reg ( qib7322, location,
- value, mask ) ) != 0 )
- return rc;
- }
- }
- return 0;
- }
-
-
-
-
- static int qib7322_init_ib_serdes ( struct qib7322 *qib7322 ) {
- struct QIB_7322_IBCCtrlA_0 ibcctrla;
- struct QIB_7322_IBCCtrlB_0 ibcctrlb;
- struct QIB_7322_IBPCSConfig_0 ibpcsconfig;
-
-
- memset ( &ibcctrla, 0, sizeof ( ibcctrla ) );
- BIT_FILL_5 ( &ibcctrla,
- FlowCtrlPeriod, 0x03,
- FlowCtrlWaterMark, 0x05,
- MaxPktLen, ( ( QIB7322_RECV_HEADER_SIZE +
- QIB7322_RECV_PAYLOAD_SIZE +
- 4 ) >> 2 ),
- PhyerrThreshold, 0xf,
- OverrunThreshold, 0xf );
- qib7322_writeq ( qib7322, &ibcctrla, QIB_7322_IBCCtrlA_0_offset );
- qib7322_writeq ( qib7322, &ibcctrla, QIB_7322_IBCCtrlA_1_offset );
-
-
-
- qib7322_readq ( qib7322, &ibcctrlb, QIB_7322_IBCCtrlB_0_offset );
- BIT_SET ( &ibcctrlb, IB_ENHANCED_MODE, 0 );
- BIT_SET ( &ibcctrlb, SD_SPEED_SDR, 1 );
- BIT_SET ( &ibcctrlb, SD_SPEED_DDR, 0 );
- BIT_SET ( &ibcctrlb, SD_SPEED_QDR, 0 );
- BIT_SET ( &ibcctrlb, IB_NUM_CHANNELS, 1 );
- BIT_SET ( &ibcctrlb, IB_LANE_REV_SUPPORTED, 0 );
- BIT_SET ( &ibcctrlb, HRTBT_ENB, 0 );
- BIT_SET ( &ibcctrlb, HRTBT_AUTO, 0 );
- qib7322_writeq ( qib7322, &ibcctrlb, QIB_7322_IBCCtrlB_0_offset );
- qib7322_writeq ( qib7322, &ibcctrlb, QIB_7322_IBCCtrlB_1_offset );
-
-
- qib7322_ahb_mod_reg_all ( qib7322, 2, 0, 0x00000e00UL );
-
-
- memset ( &ibpcsconfig, 0, sizeof ( ibpcsconfig ) );
- qib7322_writeq ( qib7322, &ibpcsconfig, QIB_7322_IBPCSConfig_0_offset );
- qib7322_writeq ( qib7322, &ibpcsconfig, QIB_7322_IBPCSConfig_1_offset );
-
- return 0;
- }
-
-
-
-
- static void qib7322_reset ( struct qib7322 *qib7322, struct pci_device *pci ) {
- struct QIB_7322_Control control;
- struct pci_config_backup backup;
-
-
- pci_backup ( pci, &backup, NULL );
-
-
- memset ( &control, 0, sizeof ( control ) );
- BIT_FILL_1 ( &control, SyncReset, 1 );
- qib7322_writeq ( qib7322, &control, QIB_7322_Control_offset );
-
-
- mdelay ( 1000 );
-
-
- pci_restore ( pci, &backup, NULL );
- }
-
-
- static int qib7322_probe ( struct pci_device *pci,
- const struct pci_device_id *id __unused ) {
- struct qib7322 *qib7322;
- struct QIB_7322_Revision revision;
- struct ib_device *ibdev;
- unsigned int link_speed_supported;
- int i;
- int rc;
-
-
- qib7322 = zalloc ( sizeof ( *qib7322 ) );
- if ( ! qib7322 ) {
- rc = -ENOMEM;
- goto err_alloc_qib7322;
- }
- pci_set_drvdata ( pci, qib7322 );
-
-
- adjust_pci_device ( pci );
-
-
- qib7322->regs = ioremap ( pci->membase, QIB7322_BAR0_SIZE );
- DBGC2 ( qib7322, "QIB7322 %p has BAR at %08lx\n",
- qib7322, pci->membase );
-
-
- qib7322_reset ( qib7322, pci );
-
-
- qib7322_readq ( qib7322, &revision, QIB_7322_Revision_offset );
- DBGC2 ( qib7322, "QIB7322 %p board %02lx v%ld.%ld.%ld.%ld\n", qib7322,
- BIT_GET ( &revision, BoardID ),
- BIT_GET ( &revision, R_SW ),
- BIT_GET ( &revision, R_Arch ),
- BIT_GET ( &revision, R_ChipRevMajor ),
- BIT_GET ( &revision, R_ChipRevMinor ) );
-
-
- if ( ( rc = qib7322_init_i2c ( qib7322 ) ) != 0 )
- goto err_init_i2c;
-
-
- if ( ( rc = qib7322_read_eeprom ( qib7322 ) ) != 0 )
- goto err_read_eeprom;
-
-
- if ( ( rc = qib7322_init_send ( qib7322 ) ) != 0 )
- goto err_init_send;
-
-
- if ( ( rc = qib7322_init_recv ( qib7322 ) ) != 0 )
- goto err_init_recv;
-
-
- if ( ( rc = qib7322_init_ib_serdes ( qib7322 ) ) != 0 )
- goto err_init_ib_serdes;
-
-
- for ( i = 0 ; i < QIB7322_MAX_PORTS ; i++ ) {
- link_speed_supported =
- qib7322_link_speed_supported ( qib7322, i );
- if ( ! link_speed_supported )
- continue;
- ibdev = alloc_ibdev ( 0 );
- if ( ! ibdev ) {
- rc = -ENOMEM;
- goto err_alloc_ibdev;
- }
- qib7322->ibdev[i] = ibdev;
- ibdev->dev = &pci->dev;
- ibdev->op = &qib7322_ib_operations;
- ibdev->port = ( QIB7322_PORT_BASE + i );
- ibdev->link_width_enabled = ibdev->link_width_supported =
- IB_LINK_WIDTH_4X;
- ibdev->link_speed_enabled = ibdev->link_speed_supported =
- IB_LINK_SPEED_SDR;
- memcpy ( &ibdev->gid.u.half[1], &qib7322->guid,
- sizeof ( ibdev->gid.u.half[1] ) );
- assert ( ( ibdev->gid.u.half[1].u.bytes[7] & i ) == 0 );
- ibdev->gid.u.half[1].u.bytes[7] |= i;
- ib_set_drvdata ( ibdev, qib7322 );
- }
-
-
- for ( i = 0 ; i < QIB7322_MAX_PORTS ; i++ ) {
- if ( ! qib7322->ibdev[i] )
- continue;
- if ( ( rc = register_ibdev ( qib7322->ibdev[i] ) ) != 0 ) {
- DBGC ( qib7322, "QIB7322 %p port %d could not register "
- "IB device: %s\n", qib7322, i, strerror ( rc ) );
- goto err_register_ibdev;
- }
- }
-
- return 0;
-
- i = QIB7322_MAX_PORTS;
- err_register_ibdev:
- for ( i-- ; i >= 0 ; i-- ) {
- if ( qib7322->ibdev[i] )
- unregister_ibdev ( qib7322->ibdev[i] );
- }
- i = QIB7322_MAX_PORTS;
- err_alloc_ibdev:
- for ( i-- ; i >= 0 ; i-- )
- ibdev_put ( qib7322->ibdev[i] );
- err_init_ib_serdes:
- qib7322_fini_send ( qib7322 );
- err_init_send:
- qib7322_fini_recv ( qib7322 );
- err_init_recv:
- err_read_eeprom:
- err_init_i2c:
- free ( qib7322 );
- err_alloc_qib7322:
- return rc;
- }
-
-
- static void qib7322_remove ( struct pci_device *pci ) {
- struct qib7322 *qib7322 = pci_get_drvdata ( pci );
- int i;
-
- for ( i = ( QIB7322_MAX_PORTS - 1 ) ; i >= 0 ; i-- ) {
- if ( qib7322->ibdev[i] )
- unregister_ibdev ( qib7322->ibdev[i] );
- }
- for ( i = ( QIB7322_MAX_PORTS - 1 ) ; i >= 0 ; i-- )
- ibdev_put ( qib7322->ibdev[i] );
- qib7322_fini_send ( qib7322 );
- qib7322_fini_recv ( qib7322 );
- free ( qib7322 );
- }
-
- static struct pci_device_id qib7322_nics[] = {
- PCI_ROM ( 0x1077, 0x7322, "iba7322", "IBA7322 QDR InfiniBand HCA", 0 ),
- };
-
- struct pci_driver qib7322_driver __pci_driver = {
- .ids = qib7322_nics,
- .id_count = ( sizeof ( qib7322_nics ) / sizeof ( qib7322_nics[0] ) ),
- .probe = qib7322_probe,
- .remove = qib7322_remove,
- };
|