123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430 |
-
-
- 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 "linda.h"
-
-
-
-
- struct linda_send_work_queue {
-
- uint8_t *send_buf;
-
- unsigned int prod;
-
- unsigned int cons;
- };
-
-
- struct linda_recv_work_queue {
-
- void *header;
-
- struct QIB_7220_scalar header_prod;
-
- unsigned int header_cons;
-
- unsigned long eager_array;
-
- unsigned int eager_entries;
-
- unsigned int eager_prod;
-
- unsigned int eager_cons;
- };
-
-
- struct linda {
-
- void *regs;
-
-
- uint8_t used_ctx[LINDA_NUM_CONTEXTS];
-
- struct linda_send_work_queue send_wq[LINDA_NUM_CONTEXTS];
-
- struct linda_recv_work_queue recv_wq[LINDA_NUM_CONTEXTS];
-
-
- unsigned long send_buffer_base;
-
- struct QIB_7220_SendBufAvail *sendbufavail;
-
- uint8_t send_buf[LINDA_MAX_SEND_BUFS];
-
- unsigned int send_buf_prod;
-
- unsigned int send_buf_cons;
-
- unsigned int reserved_send_bufs;
-
-
- struct i2c_bit_basher i2c;
-
- struct i2c_device eeprom;
- };
-
-
-
-
- static void linda_readq ( struct linda *linda, uint32_t *dwords,
- unsigned long offset ) {
- void *addr = ( linda->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 linda_readq( _linda, _ptr, _offset ) \
- linda_readq ( (_linda), (_ptr)->u.dwords, (_offset) )
- #define linda_readq_array8b( _linda, _ptr, _offset, _idx ) \
- linda_readq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) )
- #define linda_readq_array64k( _linda, _ptr, _offset, _idx ) \
- linda_readq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 65536 ) ) )
-
-
- static void linda_writeq ( struct linda *linda, const uint32_t *dwords,
- unsigned long offset ) {
- void *addr = ( linda->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 linda_writeq( _linda, _ptr, _offset ) \
- linda_writeq ( (_linda), (_ptr)->u.dwords, (_offset) )
- #define linda_writeq_array8b( _linda, _ptr, _offset, _idx ) \
- linda_writeq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) )
- #define linda_writeq_array64k( _linda, _ptr, _offset, _idx ) \
- linda_writeq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 65536 ) ) )
-
-
- static void linda_writel ( struct linda *linda, uint32_t dword,
- unsigned long offset ) {
- writel ( dword, ( linda->regs + offset ) );
- }
-
-
-
-
- static const char * linda_link_state_text ( unsigned int link_state ) {
- switch ( link_state ) {
- case LINDA_LINK_STATE_DOWN: return "DOWN";
- case LINDA_LINK_STATE_INIT: return "INIT";
- case LINDA_LINK_STATE_ARM: return "ARM";
- case LINDA_LINK_STATE_ACTIVE: return "ACTIVE";
- case LINDA_LINK_STATE_ACT_DEFER:return "ACT_DEFER";
- default: return "UNKNOWN";
- }
- }
-
-
- static void linda_link_state_changed ( struct ib_device *ibdev ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- struct QIB_7220_IBCStatus ibcstatus;
- struct QIB_7220_EXTCtrl extctrl;
- unsigned int link_state;
- unsigned int link_width;
- unsigned int link_speed;
-
-
- linda_readq ( linda, &ibcstatus, QIB_7220_IBCStatus_offset );
- link_state = BIT_GET ( &ibcstatus, LinkState );
- link_width = BIT_GET ( &ibcstatus, LinkWidthActive );
- link_speed = BIT_GET ( &ibcstatus, LinkSpeedActive );
- DBGC ( linda, "Linda %p link state %s (%s %s)\n", linda,
- linda_link_state_text ( link_state ),
- ( link_speed ? "DDR" : "SDR" ), ( link_width ? "x4" : "x1" ) );
-
-
- linda_readq ( linda, &extctrl, QIB_7220_EXTCtrl_offset );
- BIT_SET ( &extctrl, LEDPriPortGreenOn,
- ( ( link_state >= LINDA_LINK_STATE_INIT ) ? 1 : 0 ) );
- BIT_SET ( &extctrl, LEDPriPortYellowOn,
- ( ( link_state >= LINDA_LINK_STATE_ACTIVE ) ? 1 : 0 ) );
- linda_writeq ( linda, &extctrl, QIB_7220_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 linda_link_state_check ( struct linda *linda,
- unsigned int new_link_state ) {
- struct QIB_7220_IBCStatus ibcstatus;
- unsigned int link_state;
- unsigned int i;
-
- for ( i = 0 ; i < LINDA_LINK_STATE_MAX_WAIT_US ; i++ ) {
- linda_readq ( linda, &ibcstatus, QIB_7220_IBCStatus_offset );
- link_state = BIT_GET ( &ibcstatus, LinkState );
- if ( link_state == new_link_state )
- return 0;
- udelay ( 1 );
- }
-
- DBGC ( linda, "Linda %p timed out waiting for link state %s\n",
- linda, linda_link_state_text ( link_state ) );
- return -ETIMEDOUT;
- }
-
-
- static int linda_set_port_info ( struct ib_device *ibdev, union ib_mad *mad ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
- struct QIB_7220_IBCCtrl ibcctrl;
- 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 ( linda, "Linda %p set link state to %s (%x)\n", linda,
- linda_link_state_text ( link_state ), link_state );
- linda_readq ( linda, &ibcctrl, QIB_7220_IBCCtrl_offset );
- BIT_SET ( &ibcctrl, LinkCmd, link_state );
- linda_writeq ( linda, &ibcctrl, QIB_7220_IBCCtrl_offset );
-
-
-
- linda_link_state_check ( linda, link_state );
- }
-
-
- linda_link_state_changed ( ibdev );
-
- return 0;
- }
-
-
- static int linda_set_pkey_table ( struct ib_device *ibdev __unused,
- union ib_mad *mad __unused ) {
-
- return 0;
- }
-
-
-
-
- static int linda_ctx_to_qpn ( unsigned int ctx ) {
-
- return ( ctx * 2 );
- }
-
-
- static int linda_qpn_to_ctx ( unsigned int qpn ) {
-
- return ( qpn / 2 );
- }
-
-
- static int linda_alloc_ctx ( struct linda *linda ) {
- unsigned int ctx;
-
- for ( ctx = 0 ; ctx < LINDA_NUM_CONTEXTS ; ctx++ ) {
-
- if ( ! linda->used_ctx[ctx] ) {
- linda->used_ctx[ctx ] = 1;
- DBGC2 ( linda, "Linda %p CTX %d allocated\n",
- linda, ctx );
- return ctx;
- }
- }
-
- DBGC ( linda, "Linda %p out of available contexts\n", linda );
- return -ENOENT;
- }
-
-
- static void linda_free_ctx ( struct linda *linda, unsigned int ctx ) {
-
- linda->used_ctx[ctx] = 0;
- DBGC2 ( linda, "Linda %p CTX %d freed\n", linda, ctx );
- }
-
-
-
-
- #define LINDA_SEND_BUF_TOGGLE 0x80
-
-
- static unsigned int linda_alloc_send_buf ( struct linda *linda ) {
- unsigned int send_buf;
-
- send_buf = linda->send_buf[linda->send_buf_cons];
- send_buf ^= LINDA_SEND_BUF_TOGGLE;
- linda->send_buf_cons = ( ( linda->send_buf_cons + 1 ) %
- LINDA_MAX_SEND_BUFS );
- return send_buf;
- }
-
-
- static void linda_free_send_buf ( struct linda *linda,
- unsigned int send_buf ) {
- linda->send_buf[linda->send_buf_prod] = send_buf;
- linda->send_buf_prod = ( ( linda->send_buf_prod + 1 ) %
- LINDA_MAX_SEND_BUFS );
- }
-
-
- static int linda_send_buf_in_use ( struct linda *linda,
- 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 & ~LINDA_SEND_BUF_TOGGLE );
- send_check = ( !! ( send_buf & LINDA_SEND_BUF_TOGGLE ) );
- inusecheck = BIT_GET ( linda->sendbufavail, InUseCheck[send_idx] );
- inuse = ( !! ( inusecheck & 0x02 ) );
- check = ( !! ( inusecheck & 0x01 ) );
- return ( inuse || ( check != send_check ) );
- }
-
-
- static unsigned long linda_send_buffer_offset ( struct linda *linda,
- unsigned int send_buf ) {
- return ( linda->send_buffer_base +
- ( ( send_buf & ~LINDA_SEND_BUF_TOGGLE ) *
- LINDA_SEND_BUF_SIZE ) );
- }
-
-
- static int linda_create_send_wq ( struct linda *linda,
- struct ib_queue_pair *qp ) {
- struct ib_work_queue *wq = &qp->send;
- struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
- int rc;
-
-
- if ( ( linda->reserved_send_bufs + qp->send.num_wqes ) >
- LINDA_MAX_SEND_BUFS ) {
- DBGC ( linda, "Linda %p out of send buffers (have %d, used "
- "%d, need %d)\n", linda, LINDA_MAX_SEND_BUFS,
- linda->reserved_send_bufs, qp->send.num_wqes );
- rc = -ENOBUFS;
- goto err_reserve_bufs;
- }
- linda->reserved_send_bufs += qp->send.num_wqes;
-
-
- linda_wq->prod = 0;
- linda_wq->cons = 0;
-
-
- linda_wq->send_buf = zalloc ( qp->send.num_wqes *
- sizeof ( linda_wq->send_buf[0] ) );
- if ( ! linda_wq->send_buf ) {
- rc = -ENOBUFS;
- goto err_alloc_send_buf;
- }
-
- return 0;
-
- free ( linda_wq->send_buf );
- err_alloc_send_buf:
- linda->reserved_send_bufs -= qp->send.num_wqes;
- err_reserve_bufs:
- return rc;
- }
-
-
- static void linda_destroy_send_wq ( struct linda *linda,
- struct ib_queue_pair *qp ) {
- struct ib_work_queue *wq = &qp->send;
- struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
-
- free ( linda_wq->send_buf );
- linda->reserved_send_bufs -= qp->send.num_wqes;
- }
-
-
- static int linda_init_send ( struct linda *linda ) {
- struct QIB_7220_SendBufBase sendbufbase;
- struct QIB_7220_SendBufAvailAddr sendbufavailaddr;
- struct QIB_7220_SendCtrl sendctrl;
- unsigned int i;
- int rc;
-
-
- linda_readq ( linda, &sendbufbase, QIB_7220_SendBufBase_offset );
- linda->send_buffer_base = BIT_GET ( &sendbufbase,
- BaseAddr_SmallPIO );
- DBGC ( linda, "Linda %p send buffers at %lx\n",
- linda, linda->send_buffer_base );
-
-
- for ( i = 0 ; i < LINDA_MAX_SEND_BUFS ; i++ )
- linda->send_buf[i] = i;
-
-
- linda->sendbufavail = malloc_dma ( sizeof ( *linda->sendbufavail ),
- LINDA_SENDBUFAVAIL_ALIGN );
- if ( ! linda->sendbufavail ) {
- rc = -ENOMEM;
- goto err_alloc_sendbufavail;
- }
- memset ( linda->sendbufavail, 0, sizeof ( linda->sendbufavail ) );
-
-
- memset ( &sendbufavailaddr, 0, sizeof ( sendbufavailaddr ) );
- BIT_FILL_1 ( &sendbufavailaddr, SendBufAvailAddr,
- ( virt_to_bus ( linda->sendbufavail ) >> 6 ) );
- linda_writeq ( linda, &sendbufavailaddr,
- QIB_7220_SendBufAvailAddr_offset );
-
-
- memset ( &sendctrl, 0, sizeof ( sendctrl ) );
- BIT_FILL_2 ( &sendctrl,
- SendBufAvailUpd, 1,
- SPioEnable, 1 );
- linda_writeq ( linda, &sendctrl, QIB_7220_SendCtrl_offset );
-
- return 0;
-
- free_dma ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
- err_alloc_sendbufavail:
- return rc;
- }
-
-
- static void linda_fini_send ( struct linda *linda ) {
- struct QIB_7220_SendCtrl sendctrl;
-
-
- memset ( &sendctrl, 0, sizeof ( sendctrl ) );
- linda_writeq ( linda, &sendctrl, QIB_7220_SendCtrl_offset );
- mb();
-
-
- linda_readq ( linda, &sendctrl, QIB_7220_SendCtrl_offset );
-
- free_dma ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
- }
-
-
-
-
- static int linda_create_recv_wq ( struct linda *linda,
- struct ib_queue_pair *qp ) {
- struct ib_work_queue *wq = &qp->recv;
- struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7220_RcvHdrAddr0 rcvhdraddr;
- struct QIB_7220_RcvHdrTailAddr0 rcvhdrtailaddr;
- struct QIB_7220_RcvHdrHead0 rcvhdrhead;
- struct QIB_7220_scalar rcvegrindexhead;
- struct QIB_7220_RcvCtrl rcvctrl;
- unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
- int rc;
-
-
- memset ( &linda_wq->header_prod, 0,
- sizeof ( linda_wq->header_prod ) );
- linda_wq->header_cons = 0;
- linda_wq->eager_prod = 0;
- linda_wq->eager_cons = 0;
-
-
- linda_wq->header = malloc_dma ( LINDA_RECV_HEADERS_SIZE,
- LINDA_RECV_HEADERS_ALIGN );
- if ( ! linda_wq->header ) {
- rc = -ENOMEM;
- goto err_alloc_header;
- }
-
-
- memset ( &rcvhdraddr, 0, sizeof ( rcvhdraddr ) );
- BIT_FILL_1 ( &rcvhdraddr, RcvHdrAddr0,
- ( virt_to_bus ( linda_wq->header ) >> 2 ) );
- linda_writeq_array8b ( linda, &rcvhdraddr,
- QIB_7220_RcvHdrAddr0_offset, ctx );
- memset ( &rcvhdrtailaddr, 0, sizeof ( rcvhdrtailaddr ) );
- BIT_FILL_1 ( &rcvhdrtailaddr, RcvHdrTailAddr0,
- ( virt_to_bus ( &linda_wq->header_prod ) >> 2 ) );
- linda_writeq_array8b ( linda, &rcvhdrtailaddr,
- QIB_7220_RcvHdrTailAddr0_offset, ctx );
- memset ( &rcvhdrhead, 0, sizeof ( rcvhdrhead ) );
- BIT_FILL_1 ( &rcvhdrhead, counter, 1 );
- linda_writeq_array64k ( linda, &rcvhdrhead,
- QIB_7220_RcvHdrHead0_offset, ctx );
- memset ( &rcvegrindexhead, 0, sizeof ( rcvegrindexhead ) );
- BIT_FILL_1 ( &rcvegrindexhead, Value, 1 );
- linda_writeq_array64k ( linda, &rcvegrindexhead,
- QIB_7220_RcvEgrIndexHead0_offset, ctx );
- linda_readq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
- BIT_SET ( &rcvctrl, PortEnable[ctx], 1 );
- BIT_SET ( &rcvctrl, IntrAvail[ctx], 1 );
- linda_writeq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
-
- DBGC ( linda, "Linda %p QPN %ld CTX %d hdrs [%lx,%lx) prod %lx\n",
- linda, qp->qpn, ctx, virt_to_bus ( linda_wq->header ),
- ( virt_to_bus ( linda_wq->header ) + LINDA_RECV_HEADERS_SIZE ),
- virt_to_bus ( &linda_wq->header_prod ) );
- return 0;
-
- free_dma ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
- err_alloc_header:
- return rc;
- }
-
-
- static void linda_destroy_recv_wq ( struct linda *linda,
- struct ib_queue_pair *qp ) {
- struct ib_work_queue *wq = &qp->recv;
- struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7220_RcvCtrl rcvctrl;
- unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
-
-
- linda_readq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
- BIT_SET ( &rcvctrl, PortEnable[ctx], 0 );
- BIT_SET ( &rcvctrl, IntrAvail[ctx], 0 );
- linda_writeq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
-
-
- linda_readq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
- mb();
-
-
- free_dma ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
-
-
- linda_free_ctx ( linda, ctx );
- }
-
-
- static int linda_init_recv ( struct linda *linda ) {
- struct QIB_7220_RcvCtrl rcvctrl;
- struct QIB_7220_scalar rcvegrbase;
- struct QIB_7220_scalar rcvhdrentsize;
- struct QIB_7220_scalar rcvhdrcnt;
- struct QIB_7220_RcvBTHQP rcvbthqp;
- unsigned int portcfg;
- unsigned long egrbase;
- unsigned int eager_array_size_0;
- unsigned int eager_array_size_other;
- unsigned int ctx;
-
-
- switch ( LINDA_NUM_CONTEXTS ) {
- case 5:
- portcfg = LINDA_PORTCFG_5CTX;
- eager_array_size_0 = LINDA_EAGER_ARRAY_SIZE_5CTX_0;
- eager_array_size_other = LINDA_EAGER_ARRAY_SIZE_5CTX_OTHER;
- break;
- case 9:
- portcfg = LINDA_PORTCFG_9CTX;
- eager_array_size_0 = LINDA_EAGER_ARRAY_SIZE_9CTX_0;
- eager_array_size_other = LINDA_EAGER_ARRAY_SIZE_9CTX_OTHER;
- break;
- case 17:
- portcfg = LINDA_PORTCFG_17CTX;
- eager_array_size_0 = LINDA_EAGER_ARRAY_SIZE_17CTX_0;
- eager_array_size_other = LINDA_EAGER_ARRAY_SIZE_17CTX_OTHER;
- break;
- default:
- linker_assert ( 0, invalid_LINDA_NUM_CONTEXTS );
- return -EINVAL;
- }
-
-
- memset ( &rcvctrl, 0, sizeof ( rcvctrl ) );
- BIT_FILL_3 ( &rcvctrl,
- TailUpd, 1,
- PortCfg, portcfg,
- RcvQPMapEnable, 1 );
- linda_writeq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
-
-
- memset ( &rcvhdrcnt, 0, sizeof ( rcvhdrcnt ) );
- BIT_FILL_1 ( &rcvhdrcnt, Value, LINDA_RECV_HEADER_COUNT );
- linda_writeq ( linda, &rcvhdrcnt, QIB_7220_RcvHdrCnt_offset );
- memset ( &rcvhdrentsize, 0, sizeof ( rcvhdrentsize ) );
- BIT_FILL_1 ( &rcvhdrentsize, Value, ( LINDA_RECV_HEADER_SIZE >> 2 ) );
- linda_writeq ( linda, &rcvhdrentsize, QIB_7220_RcvHdrEntSize_offset );
-
-
- linda_readq ( linda, &rcvegrbase, QIB_7220_RcvEgrBase_offset );
- egrbase = BIT_GET ( &rcvegrbase, Value );
- linda->recv_wq[0].eager_array = egrbase;
- linda->recv_wq[0].eager_entries = eager_array_size_0;
- egrbase += ( eager_array_size_0 * sizeof ( struct QIB_7220_RcvEgr ) );
- for ( ctx = 1 ; ctx < LINDA_NUM_CONTEXTS ; ctx++ ) {
- linda->recv_wq[ctx].eager_array = egrbase;
- linda->recv_wq[ctx].eager_entries = eager_array_size_other;
- egrbase += ( eager_array_size_other *
- sizeof ( struct QIB_7220_RcvEgr ) );
- }
- for ( ctx = 0 ; ctx < LINDA_NUM_CONTEXTS ; ctx++ ) {
- DBGC ( linda, "Linda %p CTX %d eager array at %lx (%d "
- "entries)\n", linda, ctx,
- linda->recv_wq[ctx].eager_array,
- linda->recv_wq[ctx].eager_entries );
- }
-
-
- memset ( &rcvbthqp, 0, sizeof ( rcvbthqp ) );
- BIT_FILL_1 ( &rcvbthqp, RcvBTHQP, LINDA_QP_IDETH );
- linda_writeq ( linda, &rcvbthqp, QIB_7220_RcvBTHQP_offset );
-
- return 0;
- }
-
-
- static void linda_fini_recv ( struct linda *linda __unused ) {
-
-
- }
-
-
-
-
- static int linda_create_cq ( struct ib_device *ibdev,
- struct ib_completion_queue *cq ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- static int cqn;
-
-
-
- cq->cqn = ++cqn;
- DBGC ( linda, "Linda %p CQN %ld created\n", linda, cq->cqn );
-
- return 0;
- }
-
-
- static void linda_destroy_cq ( struct ib_device *ibdev,
- struct ib_completion_queue *cq ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
-
-
- DBGC ( linda, "Linda %p CQN %ld destroyed\n", linda, cq->cqn );
- }
-
-
-
-
- static int linda_create_qp ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- int ctx;
- int rc;
-
-
- ctx = linda_alloc_ctx ( linda );
- if ( ctx < 0 ) {
- rc = ctx;
- goto err_alloc_ctx;
- }
-
-
- qp->qpn = linda_ctx_to_qpn ( ctx );
-
-
- ib_wq_set_drvdata ( &qp->send, &linda->send_wq[ctx] );
- ib_wq_set_drvdata ( &qp->recv, &linda->recv_wq[ctx] );
-
-
- if ( ( rc = linda_create_recv_wq ( linda, qp ) ) != 0 )
- goto err_create_recv_wq;
-
-
- if ( ( rc = linda_create_send_wq ( linda, qp ) ) != 0 )
- goto err_create_send_wq;
-
- return 0;
-
- linda_destroy_send_wq ( linda, qp );
- err_create_send_wq:
- linda_destroy_recv_wq ( linda, qp );
- err_create_recv_wq:
- linda_free_ctx ( linda, ctx );
- err_alloc_ctx:
- return rc;
- }
-
-
- static int linda_modify_qp ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
-
-
-
- DBGC ( linda, "Linda %p QPN %ld modified\n", linda, qp->qpn );
- return 0;
- }
-
-
- static void linda_destroy_qp ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
-
- linda_destroy_send_wq ( linda, qp );
- linda_destroy_recv_wq ( linda, qp );
- }
-
-
-
-
- static int linda_post_send ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- struct ib_address_vector *av,
- struct io_buffer *iobuf ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->send;
- struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7220_SendPbc sendpbc;
- uint8_t header_buf[IB_MAX_HEADER_SIZE];
- struct io_buffer headers;
- unsigned int send_buf;
- unsigned long start_offset;
- unsigned long offset;
- size_t len;
- ssize_t frag_len;
- uint32_t *data;
-
-
- send_buf = linda_alloc_send_buf ( linda );
- start_offset = offset = linda_send_buffer_offset ( linda, send_buf );
-
-
- assert ( wq->iobufs[linda_wq->prod] == NULL );
- wq->iobufs[linda_wq->prod] = iobuf;
- linda_wq->send_buf[linda_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_2 ( &sendpbc,
- LengthP1_toibc, ( ( len >> 2 ) - 1 ),
- VL15, 1 );
-
-
- DBG_DISABLE ( DBGLVL_IO );
- linda_writeq ( linda, &sendpbc, offset );
- offset += sizeof ( sendpbc );
-
-
- for ( data = headers.data, frag_len = iob_len ( &headers ) ;
- frag_len > 0 ; data++, offset += 4, frag_len -= 4 ) {
- linda_writel ( linda, *data, offset );
- }
-
-
- for ( data = iobuf->data, frag_len = iob_len ( iobuf ) ;
- frag_len > 0 ; data++, offset += 4, frag_len -= 4 ) {
- linda_writel ( linda, *data, offset );
- }
- DBG_ENABLE ( DBGLVL_IO );
-
- assert ( ( start_offset + len ) == offset );
- DBGC2 ( linda, "Linda %p QPN %ld TX %d(%d) posted [%lx,%lx)\n",
- linda, qp->qpn, send_buf, linda_wq->prod,
- start_offset, offset );
-
-
- linda_wq->prod = ( ( linda_wq->prod + 1 ) & ( wq->num_wqes - 1 ) );
-
- return 0;
- }
-
-
- static void linda_complete_send ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- unsigned int wqe_idx ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->send;
- struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
- struct io_buffer *iobuf;
- unsigned int send_buf;
-
-
- send_buf = linda_wq->send_buf[wqe_idx];
- DBGC2 ( linda, "Linda %p QPN %ld TX %d(%d) complete\n",
- linda, 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;
-
-
- linda_free_send_buf ( linda, send_buf );
- }
-
-
- static void linda_poll_send_wq ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->send;
- struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
- unsigned int send_buf;
-
-
- while ( wq->fill ) {
-
-
- send_buf = linda_wq->send_buf[linda_wq->cons];
- if ( linda_send_buf_in_use ( linda, send_buf ) )
- break;
-
-
- linda_complete_send ( ibdev, qp, linda_wq->cons );
-
-
- linda_wq->cons = ( ( linda_wq->cons + 1 ) &
- ( wq->num_wqes - 1 ) );
- }
- }
-
-
- static int linda_post_recv ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- struct io_buffer *iobuf ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->recv;
- struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7220_RcvEgr rcvegr;
- struct QIB_7220_scalar rcvegrindexhead;
- unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
- 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 & ( LINDA_EAGER_BUFFER_ALIGN - 1 ) ) {
- DBGC ( linda, "Linda %p QPN %ld misaligned RX buffer "
- "(%08lx)\n", linda, qp->qpn, addr );
- return -EINVAL;
- }
- if ( len != LINDA_RECV_PAYLOAD_SIZE ) {
- DBGC ( linda, "Linda %p QPN %ld wrong RX buffer size (%zd)\n",
- linda, qp->qpn, len );
- return -EINVAL;
- }
-
-
- wqe_idx = ( linda_wq->eager_prod & ( wq->num_wqes - 1 ) );
- assert ( wq->iobufs[wqe_idx] == NULL );
-
-
- wq->iobufs[wqe_idx] = iobuf;
-
-
- switch ( LINDA_RECV_PAYLOAD_SIZE ) {
- case 2048: bufsize = LINDA_EAGER_BUFFER_2K; break;
- case 4096: bufsize = LINDA_EAGER_BUFFER_4K; break;
- case 8192: bufsize = LINDA_EAGER_BUFFER_8K; break;
- case 16384: bufsize = LINDA_EAGER_BUFFER_16K; break;
- case 32768: bufsize = LINDA_EAGER_BUFFER_32K; break;
- case 65536: bufsize = LINDA_EAGER_BUFFER_64K; break;
- default: linker_assert ( 0, invalid_rx_payload_size );
- bufsize = LINDA_EAGER_BUFFER_NONE;
- }
-
-
- memset ( &rcvegr, 0, sizeof ( rcvegr ) );
- BIT_FILL_2 ( &rcvegr,
- Addr, ( addr >> 11 ),
- BufSize, bufsize );
- linda_writeq_array8b ( linda, &rcvegr,
- linda_wq->eager_array, linda_wq->eager_prod );
- DBGC2 ( linda, "Linda %p QPN %ld RX egr %d(%d) posted [%lx,%lx)\n",
- linda, qp->qpn, linda_wq->eager_prod, wqe_idx,
- addr, ( addr + len ) );
-
-
- linda_wq->eager_prod = ( ( linda_wq->eager_prod + 1 ) &
- ( linda_wq->eager_entries - 1 ) );
-
-
- memset ( &rcvegrindexhead, 0, sizeof ( rcvegrindexhead ) );
- BIT_FILL_1 ( &rcvegrindexhead,
- Value, ( ( linda_wq->eager_prod + 1 ) &
- ( linda_wq->eager_entries - 1 ) ) );
- linda_writeq_array64k ( linda, &rcvegrindexhead,
- QIB_7220_RcvEgrIndexHead0_offset, ctx );
-
- return 0;
- }
-
-
- static void linda_complete_recv ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- unsigned int header_offs ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->recv;
- struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7220_RcvHdrFlags *rcvhdrflags;
- struct QIB_7220_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 = ( linda_wq->header + header_offs +
- LINDA_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 = ( LINDA_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 );
-
-
- if ( err || ( ! useegrbfr ) ) {
- DBGC ( linda, "Linda %p QPN %ld RX egr %d%s hdr %d type %d "
- "len %d(%d+%d+4)%s%s%s%s%s%s%s%s%s%s%s\n", linda,
- qp->qpn, egrindex, ( useegrbfr ? "" : "(unused)" ),
- ( header_offs / LINDA_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 ? "]" : "" ) );
- } else {
- DBGC2 ( linda, "Linda %p QPN %ld RX egr %d hdr %d type %d "
- "len %d(%d+%d+4)\n", linda, qp->qpn, egrindex,
- ( header_offs / LINDA_RECV_HEADER_SIZE ), rcvtype,
- pktlen, header_len, padded_payload_len );
- }
- DBGCP_HDA ( linda, 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 ( linda, "Linda %p could not parse headers: %s\n",
- linda, strerror ( rc ) );
- err = 1;
- }
- if ( ! intended_qp )
- intended_qp = qp;
-
-
-
- while ( 1 ) {
-
-
-
- if ( linda_wq->eager_cons == linda_wq->eager_prod )
- break;
-
-
-
- if ( ( linda_wq->eager_cons ==
- ( ( egrindex + 1 ) & ( linda_wq->eager_entries - 1 ) )))
- break;
-
-
-
- wqe_idx = ( linda_wq->eager_cons & ( wq->num_wqes - 1 ) );
- iobuf = wq->iobufs[wqe_idx];
- assert ( iobuf != NULL );
- wq->iobufs[wqe_idx] = NULL;
-
-
- if ( linda_wq->eager_cons == egrindex ) {
-
-
- iob_put ( iobuf, payload_len );
- rc = ( err ? -EIO : ( useegrbfr ? 0 : -ECANCELED ) );
-
- if ( qp != intended_qp ) {
- DBGC ( linda, "Linda %p redirecting QPN %ld "
- "=> %ld\n",
- linda, 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 ) );
- linda_writeq_array8b ( linda, &rcvegr, linda_wq->eager_array,
- linda_wq->eager_cons );
-
-
- linda_wq->eager_cons = ( ( linda_wq->eager_cons + 1 ) &
- ( linda_wq->eager_entries - 1 ) );
- }
- }
-
-
- static void linda_poll_recv_wq ( struct ib_device *ibdev,
- struct ib_queue_pair *qp ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- struct ib_work_queue *wq = &qp->recv;
- struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
- struct QIB_7220_RcvHdrHead0 rcvhdrhead;
- unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
- unsigned int header_prod;
-
-
- header_prod = ( BIT_GET ( &linda_wq->header_prod, Value ) << 2 );
- if ( header_prod == linda_wq->header_cons )
- return;
-
-
- while ( linda_wq->header_cons != header_prod ) {
-
-
- linda_complete_recv ( ibdev, qp, linda_wq->header_cons );
-
-
- linda_wq->header_cons += LINDA_RECV_HEADER_SIZE;
- linda_wq->header_cons %= LINDA_RECV_HEADERS_SIZE;
- }
-
-
- memset ( &rcvhdrhead, 0, sizeof ( rcvhdrhead ) );
- BIT_FILL_2 ( &rcvhdrhead,
- RcvHeadPointer, ( linda_wq->header_cons >> 2 ),
- counter, 1 );
- linda_writeq_array64k ( linda, &rcvhdrhead,
- QIB_7220_RcvHdrHead0_offset, ctx );
- }
-
-
- static void linda_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 ) {
- linda_poll_send_wq ( ibdev, wq->qp );
- } else {
- linda_poll_recv_wq ( ibdev, wq->qp );
- }
- }
- }
-
-
-
-
- static void linda_poll_eq ( struct ib_device *ibdev ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- struct QIB_7220_ErrStatus errstatus;
- struct QIB_7220_ErrClear errclear;
-
-
- DBG_DISABLE ( DBGLVL_IO );
- linda_readq ( linda, &errstatus, QIB_7220_ErrStatus_offset );
- DBG_ENABLE ( DBGLVL_IO );
- if ( BIT_GET ( &errstatus, IBStatusChanged ) ) {
- linda_link_state_changed ( ibdev );
- memset ( &errclear, 0, sizeof ( errclear ) );
- BIT_FILL_1 ( &errclear, IBStatusChangedClear, 1 );
- linda_writeq ( linda, &errclear, QIB_7220_ErrClear_offset );
- }
- }
-
-
-
-
- static int linda_open ( struct ib_device *ibdev ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- struct QIB_7220_Control control;
-
-
- linda_readq ( linda, &control, QIB_7220_Control_offset );
- BIT_SET ( &control, LinkEn, 1 );
- linda_writeq ( linda, &control, QIB_7220_Control_offset );
- return 0;
- }
-
-
- static void linda_close ( struct ib_device *ibdev ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
- struct QIB_7220_Control control;
-
-
- linda_readq ( linda, &control, QIB_7220_Control_offset );
- BIT_SET ( &control, LinkEn, 0 );
- linda_writeq ( linda, &control, QIB_7220_Control_offset );
- }
-
-
-
-
- static int linda_mcast_attach ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- union ib_gid *gid ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
-
- ( void ) linda;
- ( void ) qp;
- ( void ) gid;
- return 0;
- }
-
-
- static void linda_mcast_detach ( struct ib_device *ibdev,
- struct ib_queue_pair *qp,
- union ib_gid *gid ) {
- struct linda *linda = ib_get_drvdata ( ibdev );
-
- ( void ) linda;
- ( void ) qp;
- ( void ) gid;
- }
-
-
- static struct ib_device_operations linda_ib_operations = {
- .create_cq = linda_create_cq,
- .destroy_cq = linda_destroy_cq,
- .create_qp = linda_create_qp,
- .modify_qp = linda_modify_qp,
- .destroy_qp = linda_destroy_qp,
- .post_send = linda_post_send,
- .post_recv = linda_post_recv,
- .poll_cq = linda_poll_cq,
- .poll_eq = linda_poll_eq,
- .open = linda_open,
- .close = linda_close,
- .mcast_attach = linda_mcast_attach,
- .mcast_detach = linda_mcast_detach,
- .set_port_info = linda_set_port_info,
- .set_pkey_table = linda_set_pkey_table,
- };
-
-
-
-
- static unsigned int linda_i2c_bits[] = {
- [I2C_BIT_SCL] = ( 1 << LINDA_GPIO_SCL ),
- [I2C_BIT_SDA] = ( 1 << LINDA_GPIO_SDA ),
- };
-
-
- static int linda_i2c_read_bit ( struct bit_basher *basher,
- unsigned int bit_id ) {
- struct linda *linda =
- container_of ( basher, struct linda, i2c.basher );
- struct QIB_7220_EXTStatus extstatus;
- unsigned int status;
-
- DBG_DISABLE ( DBGLVL_IO );
-
- linda_readq ( linda, &extstatus, QIB_7220_EXTStatus_offset );
- status = ( BIT_GET ( &extstatus, GPIOIn ) & linda_i2c_bits[bit_id] );
-
- DBG_ENABLE ( DBGLVL_IO );
-
- return status;
- }
-
-
- static void linda_i2c_write_bit ( struct bit_basher *basher,
- unsigned int bit_id, unsigned long data ) {
- struct linda *linda =
- container_of ( basher, struct linda, i2c.basher );
- struct QIB_7220_EXTCtrl extctrl;
- struct QIB_7220_GPIO gpioout;
- unsigned int bit = linda_i2c_bits[bit_id];
- unsigned int outputs = 0;
- unsigned int output_enables = 0;
-
- DBG_DISABLE ( DBGLVL_IO );
-
-
- linda_readq ( linda, &extctrl, QIB_7220_EXTCtrl_offset );
- linda_readq ( linda, &gpioout, QIB_7220_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 );
-
-
-
- linda_writeq ( linda, &extctrl, QIB_7220_EXTCtrl_offset );
- linda_writeq ( linda, &gpioout, QIB_7220_GPIOOut_offset );
- mb();
-
- DBG_ENABLE ( DBGLVL_IO );
- }
-
-
- static struct bit_basher_operations linda_i2c_basher_ops = {
- .read = linda_i2c_read_bit,
- .write = linda_i2c_write_bit,
- };
-
-
- static int linda_init_i2c ( struct linda *linda ) {
- static int try_eeprom_address[] = { 0x51, 0x50 };
- unsigned int i;
- int rc;
-
-
- if ( ( rc = init_i2c_bit_basher ( &linda->i2c,
- &linda_i2c_basher_ops ) ) != 0 ) {
- DBGC ( linda, "Linda %p could not initialise I2C bus: %s\n",
- linda, strerror ( rc ) );
- return rc;
- }
-
-
- for ( i = 0 ; i < ( sizeof ( try_eeprom_address ) /
- sizeof ( try_eeprom_address[0] ) ) ; i++ ) {
- init_i2c_eeprom ( &linda->eeprom, try_eeprom_address[i] );
- if ( ( rc = i2c_check_presence ( &linda->i2c.i2c,
- &linda->eeprom ) ) == 0 ) {
- DBGC2 ( linda, "Linda %p found EEPROM at %02x\n",
- linda, try_eeprom_address[i] );
- return 0;
- }
- }
-
- DBGC ( linda, "Linda %p could not find EEPROM\n", linda );
- return -ENODEV;
- }
-
-
- static int linda_read_eeprom ( struct linda *linda, union ib_guid *guid ) {
- struct i2c_interface *i2c = &linda->i2c.i2c;
- int rc;
-
-
- if ( ( rc = i2c->read ( i2c, &linda->eeprom, LINDA_EEPROM_GUID_OFFSET,
- guid->bytes, sizeof ( *guid ) ) ) != 0 ) {
- DBGC ( linda, "Linda %p could not read GUID: %s\n",
- linda, strerror ( rc ) );
- return rc;
- }
- DBGC2 ( linda, "Linda %p has GUID " IB_GUID_FMT "\n",
- linda, IB_GUID_ARGS ( guid ) );
-
-
- if ( DBG_LOG ) {
- uint8_t serial[LINDA_EEPROM_SERIAL_SIZE + 1];
-
- serial[ sizeof ( serial ) - 1 ] = '\0';
- if ( ( rc = i2c->read ( i2c, &linda->eeprom,
- LINDA_EEPROM_SERIAL_OFFSET, serial,
- ( sizeof ( serial ) - 1 ) ) ) != 0 ) {
- DBGC ( linda, "Linda %p could not read serial: %s\n",
- linda, strerror ( rc ) );
- return rc;
- }
- DBGC2 ( linda, "Linda %p has serial number \"%s\"\n",
- linda, serial );
- }
-
- return 0;
- }
-
-
-
-
- static int linda_ib_epb_request ( struct linda *linda ) {
- struct QIB_7220_ibsd_epb_access_ctrl access;
- unsigned int i;
-
-
- memset ( &access, 0, sizeof ( access ) );
- BIT_FILL_1 ( &access, sw_ib_epb_req, 1 );
- linda_writeq ( linda, &access, QIB_7220_ibsd_epb_access_ctrl_offset );
-
-
- for ( i = 0 ; i < LINDA_EPB_REQUEST_MAX_WAIT_US ; i++ ) {
- linda_readq ( linda, &access,
- QIB_7220_ibsd_epb_access_ctrl_offset );
- if ( BIT_GET ( &access, sw_ib_epb_req_granted ) )
- return 0;
- udelay ( 1 );
- }
-
- DBGC ( linda, "Linda %p timed out waiting for IB EPB request\n",
- linda );
- return -ETIMEDOUT;
- }
-
-
- static int linda_ib_epb_wait ( struct linda *linda,
- struct QIB_7220_ibsd_epb_transaction_reg *xact ) {
- unsigned int i;
-
-
- linda_readq ( linda, xact, QIB_7220_ibsd_epb_transaction_reg_offset );
-
- for ( i = 0 ; i < LINDA_EPB_XACT_MAX_WAIT_US ; i++ ) {
- linda_readq ( linda, xact,
- QIB_7220_ibsd_epb_transaction_reg_offset );
- if ( BIT_GET ( xact, ib_epb_rdy ) ) {
- if ( BIT_GET ( xact, ib_epb_req_error ) ) {
- DBGC ( linda, "Linda %p EPB transaction "
- "failed\n", linda );
- return -EIO;
- } else {
- return 0;
- }
- }
- udelay ( 1 );
- }
-
- DBGC ( linda, "Linda %p timed out waiting for IB EPB transaction\n",
- linda );
- return -ETIMEDOUT;
- }
-
-
- static void linda_ib_epb_release ( struct linda *linda ) {
- struct QIB_7220_ibsd_epb_access_ctrl access;
-
- memset ( &access, 0, sizeof ( access ) );
- BIT_FILL_1 ( &access, sw_ib_epb_req, 0 );
- linda_writeq ( linda, &access, QIB_7220_ibsd_epb_access_ctrl_offset );
- }
-
-
- static int linda_ib_epb_read ( struct linda *linda, unsigned int location ) {
- struct QIB_7220_ibsd_epb_transaction_reg xact;
- unsigned int data;
- int rc;
-
-
- if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
- return rc;
-
-
- memset ( &xact, 0, sizeof ( xact ) );
- BIT_FILL_3 ( &xact,
- ib_epb_address, LINDA_EPB_LOC_ADDRESS ( location ),
- ib_epb_read_write, LINDA_EPB_READ,
- ib_epb_cs, LINDA_EPB_LOC_CS ( location ) );
- linda_writeq ( linda, &xact,
- QIB_7220_ibsd_epb_transaction_reg_offset );
-
-
- if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
- return rc;
-
- data = BIT_GET ( &xact, ib_epb_data );
- return data;
- }
-
-
- static int linda_ib_epb_write ( struct linda *linda, unsigned int location,
- unsigned int data ) {
- struct QIB_7220_ibsd_epb_transaction_reg xact;
- int rc;
-
-
- if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
- return rc;
-
-
- memset ( &xact, 0, sizeof ( xact ) );
- BIT_FILL_4 ( &xact,
- ib_epb_data, data,
- ib_epb_address, LINDA_EPB_LOC_ADDRESS ( location ),
- ib_epb_read_write, LINDA_EPB_WRITE,
- ib_epb_cs, LINDA_EPB_LOC_CS ( location ) );
- linda_writeq ( linda, &xact,
- QIB_7220_ibsd_epb_transaction_reg_offset );
-
-
- if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
- return rc;
-
- return 0;
- }
-
-
- static int linda_ib_epb_mod_reg ( struct linda *linda, unsigned int cs,
- unsigned int channel, unsigned int element,
- unsigned int reg, unsigned int value,
- unsigned int mask ) {
- unsigned int location;
- int old_value;
- int rc;
-
- DBG_DISABLE ( DBGLVL_IO );
-
-
- assert ( ( value & mask ) == value );
-
-
- if ( ( rc = linda_ib_epb_request ( linda ) ) != 0 )
- goto out;
-
-
- location = LINDA_EPB_LOC ( cs, channel, element, reg );
- if ( (~mask) & 0xff ) {
- old_value = linda_ib_epb_read ( linda, location );
- if ( old_value < 0 ) {
- rc = old_value;
- goto out_release;
- }
- } else {
- old_value = 0;
- }
-
-
- value = ( ( old_value & ~mask ) | value );
- DBGCP ( linda, "Linda %p CS %d EPB(%d,%d,%#02x) %#02x => %#02x\n",
- linda, cs, channel, element, reg, old_value, value );
- if ( ( rc = linda_ib_epb_write ( linda, location, value ) ) != 0 )
- goto out_release;
-
- out_release:
-
- linda_ib_epb_release ( linda );
- out:
- DBG_ENABLE ( DBGLVL_IO );
- return rc;
- }
-
-
- static int linda_ib_epb_ram_xfer ( struct linda *linda, unsigned int address,
- const void *write, void *read,
- size_t len ) {
- unsigned int control;
- unsigned int address_hi;
- unsigned int address_lo;
- int data;
- int rc;
-
- DBG_DISABLE ( DBGLVL_IO );
-
- assert ( ! ( write && read ) );
- assert ( ( address % LINDA_EPB_UC_CHUNK_SIZE ) == 0 );
- assert ( ( len % LINDA_EPB_UC_CHUNK_SIZE ) == 0 );
-
-
- if ( ( rc = linda_ib_epb_request ( linda ) ) != 0 )
- goto out;
-
-
- while ( len ) {
-
-
- if ( ( address % LINDA_EPB_UC_CHUNK_SIZE ) == 0 ) {
-
-
- control = ( read ? LINDA_EPB_UC_CTL_READ :
- LINDA_EPB_UC_CTL_WRITE );
- if ( ( rc = linda_ib_epb_write ( linda,
- LINDA_EPB_UC_CTL,
- control ) ) != 0 )
- break;
-
-
- address_hi = ( address >> 8 );
- if ( ( rc = linda_ib_epb_write ( linda,
- LINDA_EPB_UC_ADDR_HI,
- address_hi ) ) != 0 )
- break;
- address_lo = ( address & 0xff );
- if ( ( rc = linda_ib_epb_write ( linda,
- LINDA_EPB_UC_ADDR_LO,
- address_lo ) ) != 0 )
- break;
- }
-
-
- if ( read ) {
- data = linda_ib_epb_read ( linda, LINDA_EPB_UC_DATA );
- if ( data < 0 ) {
- rc = data;
- break;
- }
- *( ( uint8_t * ) read++ ) = data;
- } else {
- data = *( ( uint8_t * ) write++ );
- if ( ( rc = linda_ib_epb_write ( linda,
- LINDA_EPB_UC_DATA,
- data ) ) != 0 )
- break;
- }
- address++;
- len--;
-
-
- if ( ( address % LINDA_EPB_UC_CHUNK_SIZE ) == 0 ) {
- if ( ( rc = linda_ib_epb_write ( linda,
- LINDA_EPB_UC_CTL,
- 0 ) ) != 0 )
- break;
- }
- }
-
-
- linda_ib_epb_release ( linda );
-
- out:
- DBG_ENABLE ( DBGLVL_IO );
- return rc;
- }
-
-
-
-
- struct linda_serdes_param {
-
- uint16_t address;
-
- uint8_t value;
-
- uint8_t mask;
- } __packed;
-
-
- #define LINDA_EPB_ALL_CHANNELS 31
-
-
- #define LINDA_SERDES_PARAM_END { 0, 0, 0 }
-
-
- static int linda_set_serdes_param ( struct linda *linda,
- struct linda_serdes_param *param ) {
- unsigned int channel;
- unsigned int channel_start;
- unsigned int channel_end;
- unsigned int element;
- unsigned int reg;
- int rc;
-
-
- channel = LINDA_EPB_ADDRESS_CHANNEL ( param->address );
- element = LINDA_EPB_ADDRESS_ELEMENT ( param->address );
- reg = LINDA_EPB_ADDRESS_REG ( param->address );
- if ( channel == LINDA_EPB_ALL_CHANNELS ) {
- channel_start = 0;
- channel_end = 3;
- } else {
- channel_start = channel_end = channel;
- }
-
-
- for ( channel = channel_start ; channel <= channel_end ; channel++ ) {
- if ( ( rc = linda_ib_epb_mod_reg ( linda, LINDA_EPB_CS_SERDES,
- channel, element, reg,
- param->value,
- param->mask ) ) != 0 )
- return rc;
- }
-
- return 0;
- }
-
-
- static int linda_set_serdes_params ( struct linda *linda,
- struct linda_serdes_param *params ) {
- int rc;
-
- for ( ; params->mask != 0 ; params++ ){
- if ( ( rc = linda_set_serdes_param ( linda,
- params ) ) != 0 )
- return rc;
- }
-
- return 0;
- }
-
- #define LINDA_DDS_VAL( amp_d, main_d, ipst_d, ipre_d, \
- amp_s, main_s, ipst_s, ipre_s ) \
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x00 ), \
- ( ( ( amp_d & 0x1f ) << 1 ) | 1 ), 0xff }, \
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x01 ), \
- ( ( ( amp_s & 0x1f ) << 1 ) | 1 ), 0xff }, \
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x09 ), \
- ( ( main_d << 3 ) | 4 | ( ipre_d >> 2 ) ), 0xff }, \
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x0a ), \
- ( ( main_s << 3 ) | 4 | ( ipre_s >> 2 ) ), 0xff }, \
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x06 ), \
- ( ( ( ipst_d & 0xf ) << 1 ) | \
- ( ( ipre_d & 3 ) << 6 ) | 0x21 ), 0xff }, \
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x07 ), \
- ( ( ( ipst_s & 0xf ) << 1 ) | \
- ( ( ipre_s & 3 ) << 6) | 0x21 ), 0xff }
-
-
- static struct linda_serdes_param linda_serdes_defaults1[] = {
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x00 ), 0xd4, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x05 ), 0x2d, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x08 ), 0x03, 0x0f },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x27 ), 0x10, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x28 ), 0x30, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x0e ), 0x40, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x06 ), 0x04, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x0f ), 0x04, 0xff },
-
- LINDA_SERDES_PARAM_END
- };
- static struct linda_serdes_param linda_serdes_defaults2[] = {
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x06 ), 0x00, 0xff },
-
- LINDA_DDS_VAL ( 31, 19, 12, 0, 29, 22, 9, 0 ),
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x27 ), 0x10, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x08 ), 0x00, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x21 ), 0x00, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x09 ), 0x02, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x23 ), 0x02, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1b ), 0x0c, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1c ), 0x0c, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1e ), 0x10, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1f ), 0x10, 0xff },
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x06 ), 0x20, 0xff },
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x06 ), 0x00, 0xff },
-
- { LINDA_EPB_ADDRESS ( 7, 0, 0x15 ), 0x80, 0xff },
-
- LINDA_SERDES_PARAM_END
- };
- static struct linda_serdes_param linda_serdes_defaults3[] = {
-
- { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x27 ), 0x00, 0x38 },
-
- LINDA_SERDES_PARAM_END
- };
-
-
- static int linda_program_uc_ram ( struct linda *linda ) {
- int rc;
-
- if ( ( rc = linda_ib_epb_ram_xfer ( linda, 0, linda_ib_fw, NULL,
- sizeof ( linda_ib_fw ) ) ) != 0 ){
- DBGC ( linda, "Linda %p could not load IB firmware: %s\n",
- linda, strerror ( rc ) );
- return rc;
- }
-
- return 0;
- }
-
-
- static int linda_verify_uc_ram ( struct linda *linda ) {
- uint8_t verify[LINDA_EPB_UC_CHUNK_SIZE];
- unsigned int offset;
- int rc;
-
- for ( offset = 0 ; offset < sizeof ( linda_ib_fw );
- offset += sizeof ( verify ) ) {
- if ( ( rc = linda_ib_epb_ram_xfer ( linda, offset,
- NULL, verify,
- sizeof (verify) )) != 0 ){
- DBGC ( linda, "Linda %p could not read back IB "
- "firmware: %s\n", linda, strerror ( rc ) );
- return rc;
- }
- if ( memcmp ( ( linda_ib_fw + offset ), verify,
- sizeof ( verify ) ) != 0 ) {
- DBGC ( linda, "Linda %p firmware verification failed "
- "at offset %#x\n", linda, offset );
- DBGC_HDA ( linda, offset, ( linda_ib_fw + offset ),
- sizeof ( verify ) );
- DBGC_HDA ( linda, offset, verify, sizeof ( verify ) );
- return -EIO;
- }
- }
-
- DBGC2 ( linda, "Linda %p firmware verified ok\n", linda );
- return 0;
- }
-
-
- static int linda_trim_ib ( struct linda *linda ) {
- struct QIB_7220_IBSerDesCtrl ctrl;
- struct QIB_7220_IntStatus intstatus;
- unsigned int i;
- int rc;
-
-
- linda_readq ( linda, &ctrl, QIB_7220_IBSerDesCtrl_offset );
- BIT_SET ( &ctrl, ResetIB_uC_Core, 0 );
- linda_writeq ( linda, &ctrl, QIB_7220_IBSerDesCtrl_offset );
-
-
- for ( i = 0 ; i < LINDA_TRIM_DONE_MAX_WAIT_MS ; i++ ) {
- linda_readq ( linda, &intstatus, QIB_7220_IntStatus_offset );
- if ( BIT_GET ( &intstatus, IBSerdesTrimDone ) ) {
- rc = 0;
- goto out_reset;
- }
- mdelay ( 1 );
- }
-
- DBGC ( linda, "Linda %p timed out waiting for trim done\n", linda );
- rc = -ETIMEDOUT;
- out_reset:
-
- BIT_SET ( &ctrl, ResetIB_uC_Core, 1 );
- linda_writeq ( linda, &ctrl, QIB_7220_IBSerDesCtrl_offset );
-
- return rc;
- }
-
-
- static int linda_init_ib_serdes ( struct linda *linda ) {
- struct QIB_7220_Control control;
- struct QIB_7220_IBCCtrl ibcctrl;
- struct QIB_7220_IBCDDRCtrl ibcddrctrl;
- struct QIB_7220_XGXSCfg xgxscfg;
- int rc;
-
-
- linda_readq ( linda, &control, QIB_7220_Control_offset );
- BIT_SET ( &control, LinkEn, 0 );
- linda_writeq ( linda, &control, QIB_7220_Control_offset );
-
-
- memset ( &ibcctrl, 0, sizeof ( ibcctrl ) );
- BIT_FILL_6 ( &ibcctrl,
- FlowCtrlPeriod, 0x03,
- FlowCtrlWaterMark, 0x05,
- MaxPktLen, ( ( LINDA_RECV_HEADER_SIZE +
- LINDA_RECV_PAYLOAD_SIZE +
- 4 ) >> 2 ),
- PhyerrThreshold, 0xf,
- OverrunThreshold, 0xf,
- CreditScale, 0x4 );
- linda_writeq ( linda, &ibcctrl, QIB_7220_IBCCtrl_offset );
-
-
-
- linda_readq ( linda, &ibcddrctrl, QIB_7220_IBCDDRCtrl_offset );
- BIT_SET ( &ibcddrctrl, IB_ENHANCED_MODE, 0 );
- BIT_SET ( &ibcddrctrl, SD_SPEED_SDR, 1 );
- BIT_SET ( &ibcddrctrl, SD_SPEED_DDR, 0 );
- BIT_SET ( &ibcddrctrl, SD_SPEED_QDR, 0 );
- BIT_SET ( &ibcddrctrl, HRTBT_ENB, 0 );
- BIT_SET ( &ibcddrctrl, HRTBT_AUTO, 0 );
- linda_writeq ( linda, &ibcddrctrl, QIB_7220_IBCDDRCtrl_offset );
-
-
- if ( ( rc = linda_set_serdes_params ( linda,
- linda_serdes_defaults1 ) ) != 0 )
- return rc;
- udelay ( 415 );
- if ( ( rc = linda_set_serdes_params ( linda,
- linda_serdes_defaults2 ) ) != 0 )
- return rc;
-
-
- if ( ( rc = linda_program_uc_ram ( linda ) ) != 0 )
- return rc;
-
-
- if ( DBGLVL_LOG ) {
- if ( ( rc = linda_verify_uc_ram ( linda ) ) != 0 )
- return rc;
- }
-
-
- if ( ( rc = linda_set_serdes_params ( linda,
- linda_serdes_defaults3 ) ) != 0 )
- return rc;
-
-
- if ( ( rc = linda_trim_ib ( linda ) ) != 0 )
- return rc;
-
-
- linda_readq ( linda, &xgxscfg, QIB_7220_XGXSCfg_offset );
- BIT_SET ( &xgxscfg, tx_rx_reset, 0 );
- BIT_SET ( &xgxscfg, xcv_reset, 0 );
- linda_writeq ( linda, &xgxscfg, QIB_7220_XGXSCfg_offset );
-
- return rc;
- }
-
-
-
-
- static int linda_probe ( struct pci_device *pci ) {
- struct ib_device *ibdev;
- struct linda *linda;
- struct QIB_7220_Revision revision;
- int rc;
-
-
- ibdev = alloc_ibdev ( sizeof ( *linda ) );
- if ( ! ibdev ) {
- rc = -ENOMEM;
- goto err_alloc_ibdev;
- }
- pci_set_drvdata ( pci, ibdev );
- linda = ib_get_drvdata ( ibdev );
- ibdev->op = &linda_ib_operations;
- ibdev->dev = &pci->dev;
- ibdev->port = 1;
-
-
- adjust_pci_device ( pci );
-
-
- linda->regs = ioremap ( pci->membase, LINDA_BAR0_SIZE );
- DBGC2 ( linda, "Linda %p has BAR at %08lx\n", linda, pci->membase );
-
-
- linda_readq ( linda, &revision, QIB_7220_Revision_offset );
- DBGC2 ( linda, "Linda %p board %02lx v%ld.%ld.%ld.%ld\n", linda,
- BIT_GET ( &revision, BoardID ),
- BIT_GET ( &revision, R_SW ),
- BIT_GET ( &revision, R_Arch ),
- BIT_GET ( &revision, R_ChipRevMajor ),
- BIT_GET ( &revision, R_ChipRevMinor ) );
-
-
-
- ibdev->link_width_enabled = ibdev->link_width_supported =
- ( IB_LINK_WIDTH_4X | IB_LINK_WIDTH_1X );
- ibdev->link_speed_enabled = ibdev->link_speed_supported =
- IB_LINK_SPEED_SDR;
-
-
- if ( ( rc = linda_init_i2c ( linda ) ) != 0 )
- goto err_init_i2c;
-
-
- if ( ( rc = linda_read_eeprom ( linda, &ibdev->node_guid ) ) != 0 )
- goto err_read_eeprom;
- memcpy ( &ibdev->gid.s.guid, &ibdev->node_guid,
- sizeof ( ibdev->gid.s.guid ) );
-
-
- if ( ( rc = linda_init_send ( linda ) ) != 0 )
- goto err_init_send;
-
-
- if ( ( rc = linda_init_recv ( linda ) ) != 0 )
- goto err_init_recv;
-
-
- if ( ( rc = linda_init_ib_serdes ( linda ) ) != 0 )
- goto err_init_ib_serdes;
-
-
- if ( ( rc = register_ibdev ( ibdev ) ) != 0 ) {
- DBGC ( linda, "Linda %p could not register IB "
- "device: %s\n", linda, strerror ( rc ) );
- goto err_register_ibdev;
- }
-
- return 0;
-
- unregister_ibdev ( ibdev );
- err_register_ibdev:
- linda_fini_recv ( linda );
- err_init_recv:
- linda_fini_send ( linda );
- err_init_send:
- err_init_ib_serdes:
- err_read_eeprom:
- err_init_i2c:
- ibdev_put ( ibdev );
- err_alloc_ibdev:
- return rc;
- }
-
-
- static void linda_remove ( struct pci_device *pci ) {
- struct ib_device *ibdev = pci_get_drvdata ( pci );
- struct linda *linda = ib_get_drvdata ( ibdev );
-
- unregister_ibdev ( ibdev );
- linda_fini_recv ( linda );
- linda_fini_send ( linda );
- ibdev_put ( ibdev );
- }
-
- static struct pci_device_id linda_nics[] = {
- PCI_ROM ( 0x1077, 0x7220, "iba7220", "QLE7240/7280 HCA driver", 0 ),
- };
-
- struct pci_driver linda_driver __pci_driver = {
- .ids = linda_nics,
- .id_count = ( sizeof ( linda_nics ) / sizeof ( linda_nics[0] ) ),
- .probe = linda_probe,
- .remove = linda_remove,
- };
|