2
* Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
* You can also choose to distribute this program under the terms of
20
* the Unmodified Binary Distribution Licence (as given in the file
21
* COPYING.UBDL), provided that you have satisfied its requirements.
24
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
33
#include <ipxe/infiniband.h>
35
#include <ipxe/bitbash.h>
36
#include <ipxe/malloc.h>
37
#include <ipxe/iobuf.h>
43
* QLogic Linda Infiniband HCA
47
/** A Linda send work queue */
48
struct linda_send_work_queue {
49
/** Send buffer usage */
57
/** A Linda receive work queue */
58
struct linda_recv_work_queue {
59
/** Receive header ring */
61
/** Receive header producer offset (written by hardware) */
62
struct QIB_7220_scalar header_prod;
63
/** Receive header consumer offset */
64
unsigned int header_cons;
65
/** Offset within register space of the eager array */
66
unsigned long eager_array;
67
/** Number of entries in eager array */
68
unsigned int eager_entries;
69
/** Eager array producer index */
70
unsigned int eager_prod;
71
/** Eager array consumer index */
72
unsigned int eager_cons;
80
/** In-use contexts */
81
uint8_t used_ctx[LINDA_NUM_CONTEXTS];
82
/** Send work queues */
83
struct linda_send_work_queue send_wq[LINDA_NUM_CONTEXTS];
84
/** Receive work queues */
85
struct linda_recv_work_queue recv_wq[LINDA_NUM_CONTEXTS];
87
/** Offset within register space of the first send buffer */
88
unsigned long send_buffer_base;
89
/** Send buffer availability (reported by hardware) */
90
struct QIB_7220_SendBufAvail *sendbufavail;
91
/** Send buffer availability (maintained by software) */
92
uint8_t send_buf[LINDA_MAX_SEND_BUFS];
93
/** Send buffer availability producer counter */
94
unsigned int send_buf_prod;
95
/** Send buffer availability consumer counter */
96
unsigned int send_buf_cons;
97
/** Number of reserved send buffers (across all QPs) */
98
unsigned int reserved_send_bufs;
100
/** I2C bit-bashing interface */
101
struct i2c_bit_basher i2c;
102
/** I2C serial EEPROM */
103
struct i2c_device eeprom;
106
/***************************************************************************
108
* Linda register access
110
***************************************************************************
112
* This card requires atomic 64-bit accesses. Strange things happen
113
* if you try to use 32-bit accesses; sometimes they work, sometimes
114
* they don't, sometimes you get random data.
118
* Read Linda qword register
120
* @v linda Linda device
121
* @v qword Register buffer to read into
122
* @v offset Register offset
124
static void linda_readq ( struct linda *linda, uint64_t *qword,
125
unsigned long offset ) {
126
*qword = readq ( linda->regs + offset );
128
#define linda_readq( _linda, _ptr, _offset ) \
129
linda_readq ( (_linda), (_ptr)->u.qwords, (_offset) )
130
#define linda_readq_array8b( _linda, _ptr, _offset, _idx ) \
131
linda_readq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) )
132
#define linda_readq_array64k( _linda, _ptr, _offset, _idx ) \
133
linda_readq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 65536 ) ) )
136
* Write Linda qword register
138
* @v linda Linda device
139
* @v qword Register buffer to write
140
* @v offset Register offset
142
static void linda_writeq ( struct linda *linda, const uint64_t *qword,
143
unsigned long offset ) {
144
writeq ( *qword, ( linda->regs + offset ) );
146
#define linda_writeq( _linda, _ptr, _offset ) \
147
linda_writeq ( (_linda), (_ptr)->u.qwords, (_offset) )
148
#define linda_writeq_array8b( _linda, _ptr, _offset, _idx ) \
149
linda_writeq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) )
150
#define linda_writeq_array64k( _linda, _ptr, _offset, _idx ) \
151
linda_writeq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 65536 ) ) )
154
* Write Linda dword register
156
* @v linda Linda device
157
* @v dword Value to write
158
* @v offset Register offset
160
static void linda_writel ( struct linda *linda, uint32_t dword,
161
unsigned long offset ) {
162
writel ( dword, ( linda->regs + offset ) );
165
/***************************************************************************
167
* Link state management
169
***************************************************************************
173
* Textual representation of link state
175
* @v link_state Link state
176
* @ret link_text Link state text
178
static const char * linda_link_state_text ( unsigned int link_state ) {
179
switch ( link_state ) {
180
case LINDA_LINK_STATE_DOWN: return "DOWN";
181
case LINDA_LINK_STATE_INIT: return "INIT";
182
case LINDA_LINK_STATE_ARM: return "ARM";
183
case LINDA_LINK_STATE_ACTIVE: return "ACTIVE";
184
case LINDA_LINK_STATE_ACT_DEFER:return "ACT_DEFER";
185
default: return "UNKNOWN";
190
* Handle link state change
192
* @v linda Linda device
194
static void linda_link_state_changed ( struct ib_device *ibdev ) {
195
struct linda *linda = ib_get_drvdata ( ibdev );
196
struct QIB_7220_IBCStatus ibcstatus;
197
struct QIB_7220_EXTCtrl extctrl;
198
unsigned int link_state;
199
unsigned int link_width;
200
unsigned int link_speed;
202
/* Read link state */
203
linda_readq ( linda, &ibcstatus, QIB_7220_IBCStatus_offset );
204
link_state = BIT_GET ( &ibcstatus, LinkState );
205
link_width = BIT_GET ( &ibcstatus, LinkWidthActive );
206
link_speed = BIT_GET ( &ibcstatus, LinkSpeedActive );
207
DBGC ( linda, "Linda %p link state %s (%s %s)\n", linda,
208
linda_link_state_text ( link_state ),
209
( link_speed ? "DDR" : "SDR" ), ( link_width ? "x4" : "x1" ) );
211
/* Set LEDs according to link state */
212
linda_readq ( linda, &extctrl, QIB_7220_EXTCtrl_offset );
213
BIT_SET ( &extctrl, LEDPriPortGreenOn,
214
( ( link_state >= LINDA_LINK_STATE_INIT ) ? 1 : 0 ) );
215
BIT_SET ( &extctrl, LEDPriPortYellowOn,
216
( ( link_state >= LINDA_LINK_STATE_ACTIVE ) ? 1 : 0 ) );
217
linda_writeq ( linda, &extctrl, QIB_7220_EXTCtrl_offset );
219
/* Notify Infiniband core of link state change */
220
ibdev->port_state = ( link_state + 1 );
221
ibdev->link_width_active =
222
( link_width ? IB_LINK_WIDTH_4X : IB_LINK_WIDTH_1X );
223
ibdev->link_speed_active =
224
( link_speed ? IB_LINK_SPEED_DDR : IB_LINK_SPEED_SDR );
225
ib_link_state_changed ( ibdev );
229
* Wait for link state change to take effect
231
* @v linda Linda device
232
* @v new_link_state Expected link state
233
* @ret rc Return status code
235
static int linda_link_state_check ( struct linda *linda,
236
unsigned int new_link_state ) {
237
struct QIB_7220_IBCStatus ibcstatus;
238
unsigned int link_state;
241
for ( i = 0 ; i < LINDA_LINK_STATE_MAX_WAIT_US ; i++ ) {
242
linda_readq ( linda, &ibcstatus, QIB_7220_IBCStatus_offset );
243
link_state = BIT_GET ( &ibcstatus, LinkState );
244
if ( link_state == new_link_state )
249
DBGC ( linda, "Linda %p timed out waiting for link state %s\n",
250
linda, linda_link_state_text ( link_state ) );
255
* Set port information
257
* @v ibdev Infiniband device
258
* @v mad Set port information MAD
260
static int linda_set_port_info ( struct ib_device *ibdev, union ib_mad *mad ) {
261
struct linda *linda = ib_get_drvdata ( ibdev );
262
struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
263
struct QIB_7220_IBCCtrl ibcctrl;
264
unsigned int port_state;
265
unsigned int link_state;
267
/* Set new link state */
268
port_state = ( port_info->link_speed_supported__port_state & 0xf );
270
link_state = ( port_state - 1 );
271
DBGC ( linda, "Linda %p set link state to %s (%x)\n", linda,
272
linda_link_state_text ( link_state ), link_state );
273
linda_readq ( linda, &ibcctrl, QIB_7220_IBCCtrl_offset );
274
BIT_SET ( &ibcctrl, LinkCmd, link_state );
275
linda_writeq ( linda, &ibcctrl, QIB_7220_IBCCtrl_offset );
277
/* Wait for link state change to take effect. Ignore
278
* errors; the current link state will be returned via
279
* the GetResponse MAD.
281
linda_link_state_check ( linda, link_state );
284
/* Detect and report link state change */
285
linda_link_state_changed ( ibdev );
291
* Set partition key table
293
* @v ibdev Infiniband device
294
* @v mad Set partition key table MAD
296
static int linda_set_pkey_table ( struct ib_device *ibdev __unused,
297
union ib_mad *mad __unused ) {
302
/***************************************************************************
306
***************************************************************************
310
* Map context number to QPN
312
* @v ctx Context index
313
* @ret qpn Queue pair number
315
static int linda_ctx_to_qpn ( unsigned int ctx ) {
316
/* This mapping is fixed by hardware */
321
* Map QPN to context number
323
* @v qpn Queue pair number
324
* @ret ctx Context index
326
static int linda_qpn_to_ctx ( unsigned int qpn ) {
327
/* This mapping is fixed by hardware */
334
* @v linda Linda device
335
* @ret ctx Context index, or negative error
337
static int linda_alloc_ctx ( struct linda *linda ) {
340
for ( ctx = 0 ; ctx < LINDA_NUM_CONTEXTS ; ctx++ ) {
342
if ( ! linda->used_ctx[ctx] ) {
343
linda->used_ctx[ctx ] = 1;
344
DBGC2 ( linda, "Linda %p CTX %d allocated\n",
350
DBGC ( linda, "Linda %p out of available contexts\n", linda );
357
* @v linda Linda device
358
* @v ctx Context index
360
static void linda_free_ctx ( struct linda *linda, unsigned int ctx ) {
362
linda->used_ctx[ctx] = 0;
363
DBGC2 ( linda, "Linda %p CTX %d freed\n", linda, ctx );
366
/***************************************************************************
370
***************************************************************************
373
/** Send buffer toggle bit
375
* We encode send buffers as 7 bits of send buffer index plus a single
376
* bit which should match the "check" bit in the SendBufAvail array.
378
#define LINDA_SEND_BUF_TOGGLE 0x80
381
* Allocate a send buffer
383
* @v linda Linda device
384
* @ret send_buf Send buffer
386
* You must guarantee that a send buffer is available. This is done
387
* by refusing to allocate more TX WQEs in total than the number of
388
* available send buffers.
390
static unsigned int linda_alloc_send_buf ( struct linda *linda ) {
391
unsigned int send_buf;
393
send_buf = linda->send_buf[linda->send_buf_cons];
394
send_buf ^= LINDA_SEND_BUF_TOGGLE;
395
linda->send_buf_cons = ( ( linda->send_buf_cons + 1 ) %
396
LINDA_MAX_SEND_BUFS );
403
* @v linda Linda device
404
* @v send_buf Send buffer
406
static void linda_free_send_buf ( struct linda *linda,
407
unsigned int send_buf ) {
408
linda->send_buf[linda->send_buf_prod] = send_buf;
409
linda->send_buf_prod = ( ( linda->send_buf_prod + 1 ) %
410
LINDA_MAX_SEND_BUFS );
414
* Check to see if send buffer is in use
416
* @v linda Linda device
417
* @v send_buf Send buffer
418
* @ret in_use Send buffer is in use
420
static int linda_send_buf_in_use ( struct linda *linda,
421
unsigned int send_buf ) {
422
unsigned int send_idx;
423
unsigned int send_check;
424
unsigned int inusecheck;
428
send_idx = ( send_buf & ~LINDA_SEND_BUF_TOGGLE );
429
send_check = ( !! ( send_buf & LINDA_SEND_BUF_TOGGLE ) );
430
inusecheck = BIT_GET ( linda->sendbufavail, InUseCheck[send_idx] );
431
inuse = ( !! ( inusecheck & 0x02 ) );
432
check = ( !! ( inusecheck & 0x01 ) );
433
return ( inuse || ( check != send_check ) );
437
* Calculate starting offset for send buffer
439
* @v linda Linda device
440
* @v send_buf Send buffer
441
* @ret offset Starting offset
443
static unsigned long linda_send_buffer_offset ( struct linda *linda,
444
unsigned int send_buf ) {
445
return ( linda->send_buffer_base +
446
( ( send_buf & ~LINDA_SEND_BUF_TOGGLE ) *
447
LINDA_SEND_BUF_SIZE ) );
451
* Create send work queue
453
* @v linda Linda device
456
static int linda_create_send_wq ( struct linda *linda,
457
struct ib_queue_pair *qp ) {
458
struct ib_work_queue *wq = &qp->send;
459
struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
462
/* Reserve send buffers */
463
if ( ( linda->reserved_send_bufs + qp->send.num_wqes ) >
464
LINDA_MAX_SEND_BUFS ) {
465
DBGC ( linda, "Linda %p out of send buffers (have %d, used "
466
"%d, need %d)\n", linda, LINDA_MAX_SEND_BUFS,
467
linda->reserved_send_bufs, qp->send.num_wqes );
469
goto err_reserve_bufs;
471
linda->reserved_send_bufs += qp->send.num_wqes;
473
/* Reset work queue */
477
/* Allocate space for send buffer uasge list */
478
linda_wq->send_buf = zalloc ( qp->send.num_wqes *
479
sizeof ( linda_wq->send_buf[0] ) );
480
if ( ! linda_wq->send_buf ) {
482
goto err_alloc_send_buf;
487
free ( linda_wq->send_buf );
489
linda->reserved_send_bufs -= qp->send.num_wqes;
495
* Destroy send work queue
497
* @v linda Linda device
500
static void linda_destroy_send_wq ( struct linda *linda,
501
struct ib_queue_pair *qp ) {
502
struct ib_work_queue *wq = &qp->send;
503
struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
505
free ( linda_wq->send_buf );
506
linda->reserved_send_bufs -= qp->send.num_wqes;
510
* Initialise send datapath
512
* @v linda Linda device
513
* @ret rc Return status code
515
static int linda_init_send ( struct linda *linda ) {
516
struct QIB_7220_SendBufBase sendbufbase;
517
struct QIB_7220_SendBufAvailAddr sendbufavailaddr;
518
struct QIB_7220_SendCtrl sendctrl;
522
/* Retrieve SendBufBase */
523
linda_readq ( linda, &sendbufbase, QIB_7220_SendBufBase_offset );
524
linda->send_buffer_base = BIT_GET ( &sendbufbase,
526
DBGC ( linda, "Linda %p send buffers at %lx\n",
527
linda, linda->send_buffer_base );
529
/* Initialise the send_buf[] array */
530
for ( i = 0 ; i < LINDA_MAX_SEND_BUFS ; i++ )
531
linda->send_buf[i] = i;
533
/* Allocate space for the SendBufAvail array */
534
linda->sendbufavail = malloc_dma ( sizeof ( *linda->sendbufavail ),
535
LINDA_SENDBUFAVAIL_ALIGN );
536
if ( ! linda->sendbufavail ) {
538
goto err_alloc_sendbufavail;
540
memset ( linda->sendbufavail, 0, sizeof ( linda->sendbufavail ) );
542
/* Program SendBufAvailAddr into the hardware */
543
memset ( &sendbufavailaddr, 0, sizeof ( sendbufavailaddr ) );
544
BIT_FILL_1 ( &sendbufavailaddr, SendBufAvailAddr,
545
( virt_to_bus ( linda->sendbufavail ) >> 6 ) );
546
linda_writeq ( linda, &sendbufavailaddr,
547
QIB_7220_SendBufAvailAddr_offset );
549
/* Enable sending and DMA of SendBufAvail */
550
memset ( &sendctrl, 0, sizeof ( sendctrl ) );
551
BIT_FILL_2 ( &sendctrl,
554
linda_writeq ( linda, &sendctrl, QIB_7220_SendCtrl_offset );
558
free_dma ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
559
err_alloc_sendbufavail:
564
* Shut down send datapath
566
* @v linda Linda device
568
static void linda_fini_send ( struct linda *linda ) {
569
struct QIB_7220_SendCtrl sendctrl;
571
/* Disable sending and DMA of SendBufAvail */
572
memset ( &sendctrl, 0, sizeof ( sendctrl ) );
573
linda_writeq ( linda, &sendctrl, QIB_7220_SendCtrl_offset );
576
/* Ensure hardware has seen this disable */
577
linda_readq ( linda, &sendctrl, QIB_7220_SendCtrl_offset );
579
free_dma ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
582
/***************************************************************************
586
***************************************************************************
590
* Create receive work queue
592
* @v linda Linda device
594
* @ret rc Return status code
596
static int linda_create_recv_wq ( struct linda *linda,
597
struct ib_queue_pair *qp ) {
598
struct ib_work_queue *wq = &qp->recv;
599
struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
600
struct QIB_7220_RcvHdrAddr0 rcvhdraddr;
601
struct QIB_7220_RcvHdrTailAddr0 rcvhdrtailaddr;
602
struct QIB_7220_RcvHdrHead0 rcvhdrhead;
603
struct QIB_7220_scalar rcvegrindexhead;
604
struct QIB_7220_RcvCtrl rcvctrl;
605
unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
608
/* Reset context information */
609
memset ( &linda_wq->header_prod, 0,
610
sizeof ( linda_wq->header_prod ) );
611
linda_wq->header_cons = 0;
612
linda_wq->eager_prod = 0;
613
linda_wq->eager_cons = 0;
615
/* Allocate receive header buffer */
616
linda_wq->header = malloc_dma ( LINDA_RECV_HEADERS_SIZE,
617
LINDA_RECV_HEADERS_ALIGN );
618
if ( ! linda_wq->header ) {
620
goto err_alloc_header;
623
/* Enable context in hardware */
624
memset ( &rcvhdraddr, 0, sizeof ( rcvhdraddr ) );
625
BIT_FILL_1 ( &rcvhdraddr, RcvHdrAddr0,
626
( virt_to_bus ( linda_wq->header ) >> 2 ) );
627
linda_writeq_array8b ( linda, &rcvhdraddr,
628
QIB_7220_RcvHdrAddr0_offset, ctx );
629
memset ( &rcvhdrtailaddr, 0, sizeof ( rcvhdrtailaddr ) );
630
BIT_FILL_1 ( &rcvhdrtailaddr, RcvHdrTailAddr0,
631
( virt_to_bus ( &linda_wq->header_prod ) >> 2 ) );
632
linda_writeq_array8b ( linda, &rcvhdrtailaddr,
633
QIB_7220_RcvHdrTailAddr0_offset, ctx );
634
memset ( &rcvhdrhead, 0, sizeof ( rcvhdrhead ) );
635
BIT_FILL_1 ( &rcvhdrhead, counter, 1 );
636
linda_writeq_array64k ( linda, &rcvhdrhead,
637
QIB_7220_RcvHdrHead0_offset, ctx );
638
memset ( &rcvegrindexhead, 0, sizeof ( rcvegrindexhead ) );
639
BIT_FILL_1 ( &rcvegrindexhead, Value, 1 );
640
linda_writeq_array64k ( linda, &rcvegrindexhead,
641
QIB_7220_RcvEgrIndexHead0_offset, ctx );
642
linda_readq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
643
BIT_SET ( &rcvctrl, PortEnable[ctx], 1 );
644
BIT_SET ( &rcvctrl, IntrAvail[ctx], 1 );
645
linda_writeq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
647
DBGC ( linda, "Linda %p QPN %ld CTX %d hdrs [%lx,%lx) prod %lx\n",
648
linda, qp->qpn, ctx, virt_to_bus ( linda_wq->header ),
649
( virt_to_bus ( linda_wq->header ) + LINDA_RECV_HEADERS_SIZE ),
650
virt_to_bus ( &linda_wq->header_prod ) );
653
free_dma ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
659
* Destroy receive work queue
661
* @v linda Linda device
664
static void linda_destroy_recv_wq ( struct linda *linda,
665
struct ib_queue_pair *qp ) {
666
struct ib_work_queue *wq = &qp->recv;
667
struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
668
struct QIB_7220_RcvCtrl rcvctrl;
669
unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
671
/* Disable context in hardware */
672
linda_readq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
673
BIT_SET ( &rcvctrl, PortEnable[ctx], 0 );
674
BIT_SET ( &rcvctrl, IntrAvail[ctx], 0 );
675
linda_writeq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
677
/* Make sure the hardware has seen that the context is disabled */
678
linda_readq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
681
/* Free headers ring */
682
free_dma ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
685
linda_free_ctx ( linda, ctx );
689
* Initialise receive datapath
691
* @v linda Linda device
692
* @ret rc Return status code
694
static int linda_init_recv ( struct linda *linda ) {
695
struct QIB_7220_RcvCtrl rcvctrl;
696
struct QIB_7220_scalar rcvegrbase;
697
struct QIB_7220_scalar rcvhdrentsize;
698
struct QIB_7220_scalar rcvhdrcnt;
699
struct QIB_7220_RcvBTHQP rcvbthqp;
700
unsigned int portcfg;
701
unsigned long egrbase;
702
unsigned int eager_array_size_0;
703
unsigned int eager_array_size_other;
706
/* Select configuration based on number of contexts */
707
switch ( LINDA_NUM_CONTEXTS ) {
709
portcfg = LINDA_PORTCFG_5CTX;
710
eager_array_size_0 = LINDA_EAGER_ARRAY_SIZE_5CTX_0;
711
eager_array_size_other = LINDA_EAGER_ARRAY_SIZE_5CTX_OTHER;
714
portcfg = LINDA_PORTCFG_9CTX;
715
eager_array_size_0 = LINDA_EAGER_ARRAY_SIZE_9CTX_0;
716
eager_array_size_other = LINDA_EAGER_ARRAY_SIZE_9CTX_OTHER;
719
portcfg = LINDA_PORTCFG_17CTX;
720
eager_array_size_0 = LINDA_EAGER_ARRAY_SIZE_17CTX_0;
721
eager_array_size_other = LINDA_EAGER_ARRAY_SIZE_17CTX_OTHER;
724
linker_assert ( 0, invalid_LINDA_NUM_CONTEXTS );
728
/* Configure number of contexts */
729
memset ( &rcvctrl, 0, sizeof ( rcvctrl ) );
730
BIT_FILL_3 ( &rcvctrl,
734
linda_writeq ( linda, &rcvctrl, QIB_7220_RcvCtrl_offset );
736
/* Configure receive header buffer sizes */
737
memset ( &rcvhdrcnt, 0, sizeof ( rcvhdrcnt ) );
738
BIT_FILL_1 ( &rcvhdrcnt, Value, LINDA_RECV_HEADER_COUNT );
739
linda_writeq ( linda, &rcvhdrcnt, QIB_7220_RcvHdrCnt_offset );
740
memset ( &rcvhdrentsize, 0, sizeof ( rcvhdrentsize ) );
741
BIT_FILL_1 ( &rcvhdrentsize, Value, ( LINDA_RECV_HEADER_SIZE >> 2 ) );
742
linda_writeq ( linda, &rcvhdrentsize, QIB_7220_RcvHdrEntSize_offset );
744
/* Calculate eager array start addresses for each context */
745
linda_readq ( linda, &rcvegrbase, QIB_7220_RcvEgrBase_offset );
746
egrbase = BIT_GET ( &rcvegrbase, Value );
747
linda->recv_wq[0].eager_array = egrbase;
748
linda->recv_wq[0].eager_entries = eager_array_size_0;
749
egrbase += ( eager_array_size_0 * sizeof ( struct QIB_7220_RcvEgr ) );
750
for ( ctx = 1 ; ctx < LINDA_NUM_CONTEXTS ; ctx++ ) {
751
linda->recv_wq[ctx].eager_array = egrbase;
752
linda->recv_wq[ctx].eager_entries = eager_array_size_other;
753
egrbase += ( eager_array_size_other *
754
sizeof ( struct QIB_7220_RcvEgr ) );
756
for ( ctx = 0 ; ctx < LINDA_NUM_CONTEXTS ; ctx++ ) {
757
DBGC ( linda, "Linda %p CTX %d eager array at %lx (%d "
758
"entries)\n", linda, ctx,
759
linda->recv_wq[ctx].eager_array,
760
linda->recv_wq[ctx].eager_entries );
763
/* Set the BTH QP for Infinipath packets to an unused value */
764
memset ( &rcvbthqp, 0, sizeof ( rcvbthqp ) );
765
BIT_FILL_1 ( &rcvbthqp, RcvBTHQP, LINDA_QP_IDETH );
766
linda_writeq ( linda, &rcvbthqp, QIB_7220_RcvBTHQP_offset );
772
* Shut down receive datapath
774
* @v linda Linda device
776
static void linda_fini_recv ( struct linda *linda __unused ) {
777
/* Nothing to do; all contexts were already disabled when the
778
* queue pairs were destroyed
782
/***************************************************************************
784
* Completion queue operations
786
***************************************************************************
790
* Create completion queue
792
* @v ibdev Infiniband device
793
* @v cq Completion queue
794
* @ret rc Return status code
796
static int linda_create_cq ( struct ib_device *ibdev,
797
struct ib_completion_queue *cq ) {
798
struct linda *linda = ib_get_drvdata ( ibdev );
801
/* The hardware has no concept of completion queues. We
802
* simply use the association between CQs and WQs (already
803
* handled by the IB core) to decide which WQs to poll.
805
* We do set a CQN, just to avoid confusing debug messages
809
DBGC ( linda, "Linda %p CQN %ld created\n", linda, cq->cqn );
815
* Destroy completion queue
817
* @v ibdev Infiniband device
818
* @v cq Completion queue
820
static void linda_destroy_cq ( struct ib_device *ibdev,
821
struct ib_completion_queue *cq ) {
822
struct linda *linda = ib_get_drvdata ( ibdev );
825
DBGC ( linda, "Linda %p CQN %ld destroyed\n", linda, cq->cqn );
828
/***************************************************************************
830
* Queue pair operations
832
***************************************************************************
838
* @v ibdev Infiniband device
840
* @ret rc Return status code
842
static int linda_create_qp ( struct ib_device *ibdev,
843
struct ib_queue_pair *qp ) {
844
struct linda *linda = ib_get_drvdata ( ibdev );
848
/* Locate an available context */
849
ctx = linda_alloc_ctx ( linda );
855
/* Set queue pair number based on context index */
856
qp->qpn = linda_ctx_to_qpn ( ctx );
858
/* Set work-queue private data pointers */
859
ib_wq_set_drvdata ( &qp->send, &linda->send_wq[ctx] );
860
ib_wq_set_drvdata ( &qp->recv, &linda->recv_wq[ctx] );
862
/* Create receive work queue */
863
if ( ( rc = linda_create_recv_wq ( linda, qp ) ) != 0 )
864
goto err_create_recv_wq;
866
/* Create send work queue */
867
if ( ( rc = linda_create_send_wq ( linda, qp ) ) != 0 )
868
goto err_create_send_wq;
872
linda_destroy_send_wq ( linda, qp );
874
linda_destroy_recv_wq ( linda, qp );
876
linda_free_ctx ( linda, ctx );
884
* @v ibdev Infiniband device
886
* @ret rc Return status code
888
static int linda_modify_qp ( struct ib_device *ibdev,
889
struct ib_queue_pair *qp ) {
890
struct linda *linda = ib_get_drvdata ( ibdev );
892
/* Nothing to do; the hardware doesn't have a notion of queue
895
DBGC ( linda, "Linda %p QPN %ld modified\n", linda, qp->qpn );
902
* @v ibdev Infiniband device
905
static void linda_destroy_qp ( struct ib_device *ibdev,
906
struct ib_queue_pair *qp ) {
907
struct linda *linda = ib_get_drvdata ( ibdev );
909
linda_destroy_send_wq ( linda, qp );
910
linda_destroy_recv_wq ( linda, qp );
913
/***************************************************************************
915
* Work request operations
917
***************************************************************************
921
* Post send work queue entry
923
* @v ibdev Infiniband device
925
* @v dest Destination address vector
926
* @v iobuf I/O buffer
927
* @ret rc Return status code
929
static int linda_post_send ( struct ib_device *ibdev,
930
struct ib_queue_pair *qp,
931
struct ib_address_vector *dest,
932
struct io_buffer *iobuf ) {
933
struct linda *linda = ib_get_drvdata ( ibdev );
934
struct ib_work_queue *wq = &qp->send;
935
struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
936
struct QIB_7220_SendPbc sendpbc;
937
uint8_t header_buf[IB_MAX_HEADER_SIZE];
938
struct io_buffer headers;
939
unsigned int send_buf;
940
unsigned long start_offset;
941
unsigned long offset;
946
/* Allocate send buffer and calculate offset */
947
send_buf = linda_alloc_send_buf ( linda );
948
start_offset = offset = linda_send_buffer_offset ( linda, send_buf );
950
/* Store I/O buffer and send buffer index */
951
assert ( wq->iobufs[linda_wq->prod] == NULL );
952
wq->iobufs[linda_wq->prod] = iobuf;
953
linda_wq->send_buf[linda_wq->prod] = send_buf;
955
/* Construct headers */
956
iob_populate ( &headers, header_buf, 0, sizeof ( header_buf ) );
957
iob_reserve ( &headers, sizeof ( header_buf ) );
958
ib_push ( ibdev, &headers, qp, iob_len ( iobuf ), dest );
960
/* Calculate packet length */
961
len = ( ( sizeof ( sendpbc ) + iob_len ( &headers ) +
962
iob_len ( iobuf ) + 3 ) & ~3 );
964
/* Construct send per-buffer control word */
965
memset ( &sendpbc, 0, sizeof ( sendpbc ) );
966
BIT_FILL_2 ( &sendpbc,
967
LengthP1_toibc, ( ( len >> 2 ) - 1 ),
971
DBG_DISABLE ( DBGLVL_IO );
972
linda_writeq ( linda, &sendpbc, offset );
973
offset += sizeof ( sendpbc );
976
for ( data = headers.data, frag_len = iob_len ( &headers ) ;
977
frag_len > 0 ; data++, offset += 4, frag_len -= 4 ) {
978
linda_writel ( linda, *data, offset );
982
for ( data = iobuf->data, frag_len = iob_len ( iobuf ) ;
983
frag_len > 0 ; data++, offset += 4, frag_len -= 4 ) {
984
linda_writel ( linda, *data, offset );
986
DBG_ENABLE ( DBGLVL_IO );
988
assert ( ( start_offset + len ) == offset );
989
DBGC2 ( linda, "Linda %p QPN %ld TX %d(%d) posted [%lx,%lx)\n",
990
linda, qp->qpn, send_buf, linda_wq->prod,
991
start_offset, offset );
993
/* Increment producer counter */
994
linda_wq->prod = ( ( linda_wq->prod + 1 ) & ( wq->num_wqes - 1 ) );
1000
* Complete send work queue entry
1002
* @v ibdev Infiniband device
1004
* @v wqe_idx Work queue entry index
1006
static void linda_complete_send ( struct ib_device *ibdev,
1007
struct ib_queue_pair *qp,
1008
unsigned int wqe_idx ) {
1009
struct linda *linda = ib_get_drvdata ( ibdev );
1010
struct ib_work_queue *wq = &qp->send;
1011
struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
1012
struct io_buffer *iobuf;
1013
unsigned int send_buf;
1015
/* Parse completion */
1016
send_buf = linda_wq->send_buf[wqe_idx];
1017
DBGC2 ( linda, "Linda %p QPN %ld TX %d(%d) complete\n",
1018
linda, qp->qpn, send_buf, wqe_idx );
1020
/* Complete work queue entry */
1021
iobuf = wq->iobufs[wqe_idx];
1022
assert ( iobuf != NULL );
1023
ib_complete_send ( ibdev, qp, iobuf, 0 );
1024
wq->iobufs[wqe_idx] = NULL;
1026
/* Free send buffer */
1027
linda_free_send_buf ( linda, send_buf );
1031
* Poll send work queue
1033
* @v ibdev Infiniband device
1036
static void linda_poll_send_wq ( struct ib_device *ibdev,
1037
struct ib_queue_pair *qp ) {
1038
struct linda *linda = ib_get_drvdata ( ibdev );
1039
struct ib_work_queue *wq = &qp->send;
1040
struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
1041
unsigned int send_buf;
1043
/* Look for completions */
1044
while ( wq->fill ) {
1046
/* Check to see if send buffer has completed */
1047
send_buf = linda_wq->send_buf[linda_wq->cons];
1048
if ( linda_send_buf_in_use ( linda, send_buf ) )
1051
/* Complete this buffer */
1052
linda_complete_send ( ibdev, qp, linda_wq->cons );
1054
/* Increment consumer counter */
1055
linda_wq->cons = ( ( linda_wq->cons + 1 ) &
1056
( wq->num_wqes - 1 ) );
1061
* Post receive work queue entry
1063
* @v ibdev Infiniband device
1065
* @v iobuf I/O buffer
1066
* @ret rc Return status code
1068
static int linda_post_recv ( struct ib_device *ibdev,
1069
struct ib_queue_pair *qp,
1070
struct io_buffer *iobuf ) {
1071
struct linda *linda = ib_get_drvdata ( ibdev );
1072
struct ib_work_queue *wq = &qp->recv;
1073
struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
1074
struct QIB_7220_RcvEgr rcvegr;
1075
struct QIB_7220_scalar rcvegrindexhead;
1076
unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
1079
unsigned int wqe_idx;
1080
unsigned int bufsize;
1083
addr = virt_to_bus ( iobuf->data );
1084
len = iob_tailroom ( iobuf );
1085
if ( addr & ( LINDA_EAGER_BUFFER_ALIGN - 1 ) ) {
1086
DBGC ( linda, "Linda %p QPN %ld misaligned RX buffer "
1087
"(%08lx)\n", linda, qp->qpn, addr );
1090
if ( len != LINDA_RECV_PAYLOAD_SIZE ) {
1091
DBGC ( linda, "Linda %p QPN %ld wrong RX buffer size (%zd)\n",
1092
linda, qp->qpn, len );
1096
/* Calculate eager producer index and WQE index */
1097
wqe_idx = ( linda_wq->eager_prod & ( wq->num_wqes - 1 ) );
1098
assert ( wq->iobufs[wqe_idx] == NULL );
1100
/* Store I/O buffer */
1101
wq->iobufs[wqe_idx] = iobuf;
1103
/* Calculate buffer size */
1104
switch ( LINDA_RECV_PAYLOAD_SIZE ) {
1105
case 2048: bufsize = LINDA_EAGER_BUFFER_2K; break;
1106
case 4096: bufsize = LINDA_EAGER_BUFFER_4K; break;
1107
case 8192: bufsize = LINDA_EAGER_BUFFER_8K; break;
1108
case 16384: bufsize = LINDA_EAGER_BUFFER_16K; break;
1109
case 32768: bufsize = LINDA_EAGER_BUFFER_32K; break;
1110
case 65536: bufsize = LINDA_EAGER_BUFFER_64K; break;
1111
default: linker_assert ( 0, invalid_rx_payload_size );
1112
bufsize = LINDA_EAGER_BUFFER_NONE;
1115
/* Post eager buffer */
1116
memset ( &rcvegr, 0, sizeof ( rcvegr ) );
1117
BIT_FILL_2 ( &rcvegr,
1118
Addr, ( addr >> 11 ),
1120
linda_writeq_array8b ( linda, &rcvegr,
1121
linda_wq->eager_array, linda_wq->eager_prod );
1122
DBGC2 ( linda, "Linda %p QPN %ld RX egr %d(%d) posted [%lx,%lx)\n",
1123
linda, qp->qpn, linda_wq->eager_prod, wqe_idx,
1124
addr, ( addr + len ) );
1126
/* Increment producer index */
1127
linda_wq->eager_prod = ( ( linda_wq->eager_prod + 1 ) &
1128
( linda_wq->eager_entries - 1 ) );
1130
/* Update head index */
1131
memset ( &rcvegrindexhead, 0, sizeof ( rcvegrindexhead ) );
1132
BIT_FILL_1 ( &rcvegrindexhead,
1133
Value, ( ( linda_wq->eager_prod + 1 ) &
1134
( linda_wq->eager_entries - 1 ) ) );
1135
linda_writeq_array64k ( linda, &rcvegrindexhead,
1136
QIB_7220_RcvEgrIndexHead0_offset, ctx );
1142
* Complete receive work queue entry
1144
* @v ibdev Infiniband device
1146
* @v header_offs Header offset
1148
static void linda_complete_recv ( struct ib_device *ibdev,
1149
struct ib_queue_pair *qp,
1150
unsigned int header_offs ) {
1151
struct linda *linda = ib_get_drvdata ( ibdev );
1152
struct ib_work_queue *wq = &qp->recv;
1153
struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
1154
struct QIB_7220_RcvHdrFlags *rcvhdrflags;
1155
struct QIB_7220_RcvEgr rcvegr;
1156
struct io_buffer headers;
1157
struct io_buffer *iobuf;
1158
struct ib_queue_pair *intended_qp;
1159
struct ib_address_vector dest;
1160
struct ib_address_vector source;
1161
unsigned int rcvtype;
1162
unsigned int pktlen;
1163
unsigned int egrindex;
1164
unsigned int useegrbfr;
1165
unsigned int iberr, mkerr, tiderr, khdrerr, mtuerr;
1166
unsigned int lenerr, parityerr, vcrcerr, icrcerr;
1168
unsigned int hdrqoffset;
1169
unsigned int header_len;
1170
unsigned int padded_payload_len;
1171
unsigned int wqe_idx;
1176
/* RcvHdrFlags are at the end of the header entry */
1177
rcvhdrflags = ( linda_wq->header + header_offs +
1178
LINDA_RECV_HEADER_SIZE - sizeof ( *rcvhdrflags ) );
1179
rcvtype = BIT_GET ( rcvhdrflags, RcvType );
1180
pktlen = ( BIT_GET ( rcvhdrflags, PktLen ) << 2 );
1181
egrindex = BIT_GET ( rcvhdrflags, EgrIndex );
1182
useegrbfr = BIT_GET ( rcvhdrflags, UseEgrBfr );
1183
hdrqoffset = ( BIT_GET ( rcvhdrflags, HdrqOffset ) << 2 );
1184
iberr = BIT_GET ( rcvhdrflags, IBErr );
1185
mkerr = BIT_GET ( rcvhdrflags, MKErr );
1186
tiderr = BIT_GET ( rcvhdrflags, TIDErr );
1187
khdrerr = BIT_GET ( rcvhdrflags, KHdrErr );
1188
mtuerr = BIT_GET ( rcvhdrflags, MTUErr );
1189
lenerr = BIT_GET ( rcvhdrflags, LenErr );
1190
parityerr = BIT_GET ( rcvhdrflags, ParityErr );
1191
vcrcerr = BIT_GET ( rcvhdrflags, VCRCErr );
1192
icrcerr = BIT_GET ( rcvhdrflags, ICRCErr );
1193
header_len = ( LINDA_RECV_HEADER_SIZE - hdrqoffset -
1194
sizeof ( *rcvhdrflags ) );
1195
padded_payload_len = ( pktlen - header_len - 4 /* ICRC */ );
1196
err = ( iberr | mkerr | tiderr | khdrerr | mtuerr |
1197
lenerr | parityerr | vcrcerr | icrcerr );
1198
/* IB header is placed immediately before RcvHdrFlags */
1199
iob_populate ( &headers, ( ( ( void * ) rcvhdrflags ) - header_len ),
1200
header_len, header_len );
1202
/* Dump diagnostic information */
1203
if ( err || ( ! useegrbfr ) ) {
1204
DBGC ( linda, "Linda %p QPN %ld RX egr %d%s hdr %d type %d "
1205
"len %d(%d+%d+4)%s%s%s%s%s%s%s%s%s%s%s\n", linda,
1206
qp->qpn, egrindex, ( useegrbfr ? "" : "(unused)" ),
1207
( header_offs / LINDA_RECV_HEADER_SIZE ), rcvtype,
1208
pktlen, header_len, padded_payload_len,
1209
( err ? " [Err" : "" ), ( iberr ? " IB" : "" ),
1210
( mkerr ? " MK" : "" ), ( tiderr ? " TID" : "" ),
1211
( khdrerr ? " KHdr" : "" ), ( mtuerr ? " MTU" : "" ),
1212
( lenerr ? " Len" : "" ), ( parityerr ? " Parity" : ""),
1213
( vcrcerr ? " VCRC" : "" ), ( icrcerr ? " ICRC" : "" ),
1214
( err ? "]" : "" ) );
1216
DBGC2 ( linda, "Linda %p QPN %ld RX egr %d hdr %d type %d "
1217
"len %d(%d+%d+4)\n", linda, qp->qpn, egrindex,
1218
( header_offs / LINDA_RECV_HEADER_SIZE ), rcvtype,
1219
pktlen, header_len, padded_payload_len );
1221
DBGCP_HDA ( linda, hdrqoffset, headers.data,
1222
( header_len + sizeof ( *rcvhdrflags ) ) );
1224
/* Parse header to generate address vector */
1225
qp0 = ( qp->qpn == 0 );
1227
if ( ( rc = ib_pull ( ibdev, &headers, ( qp0 ? &intended_qp : NULL ),
1228
&payload_len, &dest, &source ) ) != 0 ) {
1229
DBGC ( linda, "Linda %p could not parse headers: %s\n",
1230
linda, strerror ( rc ) );
1233
if ( ! intended_qp )
1236
/* Complete this buffer and any skipped buffers. Note that
1237
* when the hardware runs out of buffers, it will repeatedly
1238
* report the same buffer (the tail) as a TID error, and that
1239
* it also has a habit of sometimes skipping over several
1244
/* If we have caught up to the producer counter, stop.
1245
* This will happen when the hardware first runs out
1246
* of buffers and starts reporting TID errors against
1247
* the eager buffer it wants to use next.
1249
if ( linda_wq->eager_cons == linda_wq->eager_prod )
1252
/* If we have caught up to where we should be after
1253
* completing this egrindex, stop. We phrase the test
1254
* this way to avoid completing the entire ring when
1255
* we receive the same egrindex twice in a row.
1257
if ( ( linda_wq->eager_cons ==
1258
( ( egrindex + 1 ) & ( linda_wq->eager_entries - 1 ) )))
1261
/* Identify work queue entry and corresponding I/O
1264
wqe_idx = ( linda_wq->eager_cons & ( wq->num_wqes - 1 ) );
1265
iobuf = wq->iobufs[wqe_idx];
1266
assert ( iobuf != NULL );
1267
wq->iobufs[wqe_idx] = NULL;
1269
/* Complete the eager buffer */
1270
if ( linda_wq->eager_cons == egrindex ) {
1271
/* Completing the eager buffer described in
1272
* this header entry.
1274
if ( payload_len <= iob_tailroom ( iobuf ) ) {
1275
iob_put ( iobuf, payload_len );
1277
-EIO : ( useegrbfr ? 0 : -ECANCELED ) );
1279
DBGC ( linda, "Linda %p bad payload len %zd\n",
1280
linda, payload_len );
1283
/* Redirect to target QP if necessary */
1284
if ( qp != intended_qp ) {
1285
DBGC ( linda, "Linda %p redirecting QPN %ld "
1287
linda, qp->qpn, intended_qp->qpn );
1288
/* Compensate for incorrect fill levels */
1290
intended_qp->recv.fill++;
1292
ib_complete_recv ( ibdev, intended_qp, &dest, &source,
1295
/* Completing on a skipped-over eager buffer */
1296
ib_complete_recv ( ibdev, qp, &dest, &source, iobuf,
1300
/* Clear eager buffer */
1301
memset ( &rcvegr, 0, sizeof ( rcvegr ) );
1302
linda_writeq_array8b ( linda, &rcvegr, linda_wq->eager_array,
1303
linda_wq->eager_cons );
1305
/* Increment consumer index */
1306
linda_wq->eager_cons = ( ( linda_wq->eager_cons + 1 ) &
1307
( linda_wq->eager_entries - 1 ) );
1312
* Poll receive work queue
1314
* @v ibdev Infiniband device
1317
static void linda_poll_recv_wq ( struct ib_device *ibdev,
1318
struct ib_queue_pair *qp ) {
1319
struct linda *linda = ib_get_drvdata ( ibdev );
1320
struct ib_work_queue *wq = &qp->recv;
1321
struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
1322
struct QIB_7220_RcvHdrHead0 rcvhdrhead;
1323
unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
1324
unsigned int header_prod;
1326
/* Check for received packets */
1327
header_prod = ( BIT_GET ( &linda_wq->header_prod, Value ) << 2 );
1328
if ( header_prod == linda_wq->header_cons )
1331
/* Process all received packets */
1332
while ( linda_wq->header_cons != header_prod ) {
1334
/* Complete the receive */
1335
linda_complete_recv ( ibdev, qp, linda_wq->header_cons );
1337
/* Increment the consumer offset */
1338
linda_wq->header_cons += LINDA_RECV_HEADER_SIZE;
1339
linda_wq->header_cons %= LINDA_RECV_HEADERS_SIZE;
1342
/* Update consumer offset */
1343
memset ( &rcvhdrhead, 0, sizeof ( rcvhdrhead ) );
1344
BIT_FILL_2 ( &rcvhdrhead,
1345
RcvHeadPointer, ( linda_wq->header_cons >> 2 ),
1347
linda_writeq_array64k ( linda, &rcvhdrhead,
1348
QIB_7220_RcvHdrHead0_offset, ctx );
1352
* Poll completion queue
1354
* @v ibdev Infiniband device
1355
* @v cq Completion queue
1357
static void linda_poll_cq ( struct ib_device *ibdev,
1358
struct ib_completion_queue *cq ) {
1359
struct ib_work_queue *wq;
1361
/* Poll associated send and receive queues */
1362
list_for_each_entry ( wq, &cq->work_queues, list ) {
1363
if ( wq->is_send ) {
1364
linda_poll_send_wq ( ibdev, wq->qp );
1366
linda_poll_recv_wq ( ibdev, wq->qp );
1371
/***************************************************************************
1375
***************************************************************************
1381
* @v ibdev Infiniband device
1383
static void linda_poll_eq ( struct ib_device *ibdev ) {
1384
struct linda *linda = ib_get_drvdata ( ibdev );
1385
struct QIB_7220_ErrStatus errstatus;
1386
struct QIB_7220_ErrClear errclear;
1388
/* Check for link status changes */
1389
DBG_DISABLE ( DBGLVL_IO );
1390
linda_readq ( linda, &errstatus, QIB_7220_ErrStatus_offset );
1391
DBG_ENABLE ( DBGLVL_IO );
1392
if ( BIT_GET ( &errstatus, IBStatusChanged ) ) {
1393
linda_link_state_changed ( ibdev );
1394
memset ( &errclear, 0, sizeof ( errclear ) );
1395
BIT_FILL_1 ( &errclear, IBStatusChangedClear, 1 );
1396
linda_writeq ( linda, &errclear, QIB_7220_ErrClear_offset );
1400
/***************************************************************************
1402
* Infiniband link-layer operations
1404
***************************************************************************
1408
* Initialise Infiniband link
1410
* @v ibdev Infiniband device
1411
* @ret rc Return status code
1413
static int linda_open ( struct ib_device *ibdev ) {
1414
struct linda *linda = ib_get_drvdata ( ibdev );
1415
struct QIB_7220_Control control;
1418
linda_readq ( linda, &control, QIB_7220_Control_offset );
1419
BIT_SET ( &control, LinkEn, 1 );
1420
linda_writeq ( linda, &control, QIB_7220_Control_offset );
1425
* Close Infiniband link
1427
* @v ibdev Infiniband device
1429
static void linda_close ( struct ib_device *ibdev ) {
1430
struct linda *linda = ib_get_drvdata ( ibdev );
1431
struct QIB_7220_Control control;
1434
linda_readq ( linda, &control, QIB_7220_Control_offset );
1435
BIT_SET ( &control, LinkEn, 0 );
1436
linda_writeq ( linda, &control, QIB_7220_Control_offset );
1439
/***************************************************************************
1441
* Multicast group operations
1443
***************************************************************************
1447
* Attach to multicast group
1449
* @v ibdev Infiniband device
1451
* @v gid Multicast GID
1452
* @ret rc Return status code
1454
static int linda_mcast_attach ( struct ib_device *ibdev,
1455
struct ib_queue_pair *qp,
1456
union ib_gid *gid ) {
1457
struct linda *linda = ib_get_drvdata ( ibdev );
1466
* Detach from multicast group
1468
* @v ibdev Infiniband device
1470
* @v gid Multicast GID
1472
static void linda_mcast_detach ( struct ib_device *ibdev,
1473
struct ib_queue_pair *qp,
1474
union ib_gid *gid ) {
1475
struct linda *linda = ib_get_drvdata ( ibdev );
1482
/** Linda Infiniband operations */
1483
static struct ib_device_operations linda_ib_operations = {
1484
.create_cq = linda_create_cq,
1485
.destroy_cq = linda_destroy_cq,
1486
.create_qp = linda_create_qp,
1487
.modify_qp = linda_modify_qp,
1488
.destroy_qp = linda_destroy_qp,
1489
.post_send = linda_post_send,
1490
.post_recv = linda_post_recv,
1491
.poll_cq = linda_poll_cq,
1492
.poll_eq = linda_poll_eq,
1494
.close = linda_close,
1495
.mcast_attach = linda_mcast_attach,
1496
.mcast_detach = linda_mcast_detach,
1497
.set_port_info = linda_set_port_info,
1498
.set_pkey_table = linda_set_pkey_table,
1501
/***************************************************************************
1503
* I2C bus operations
1505
***************************************************************************
1508
/** Linda I2C bit to GPIO mappings */
1509
static unsigned int linda_i2c_bits[] = {
1510
[I2C_BIT_SCL] = ( 1 << LINDA_GPIO_SCL ),
1511
[I2C_BIT_SDA] = ( 1 << LINDA_GPIO_SDA ),
1515
* Read Linda I2C line status
1517
* @v basher Bit-bashing interface
1518
* @v bit_id Bit number
1519
* @ret zero Input is a logic 0
1520
* @ret non-zero Input is a logic 1
1522
static int linda_i2c_read_bit ( struct bit_basher *basher,
1523
unsigned int bit_id ) {
1524
struct linda *linda =
1525
container_of ( basher, struct linda, i2c.basher );
1526
struct QIB_7220_EXTStatus extstatus;
1527
unsigned int status;
1529
DBG_DISABLE ( DBGLVL_IO );
1531
linda_readq ( linda, &extstatus, QIB_7220_EXTStatus_offset );
1532
status = ( BIT_GET ( &extstatus, GPIOIn ) & linda_i2c_bits[bit_id] );
1534
DBG_ENABLE ( DBGLVL_IO );
1540
* Write Linda I2C line status
1542
* @v basher Bit-bashing interface
1543
* @v bit_id Bit number
1544
* @v data Value to write
1546
static void linda_i2c_write_bit ( struct bit_basher *basher,
1547
unsigned int bit_id, unsigned long data ) {
1548
struct linda *linda =
1549
container_of ( basher, struct linda, i2c.basher );
1550
struct QIB_7220_EXTCtrl extctrl;
1551
struct QIB_7220_GPIO gpioout;
1552
unsigned int bit = linda_i2c_bits[bit_id];
1553
unsigned int outputs = 0;
1554
unsigned int output_enables = 0;
1556
DBG_DISABLE ( DBGLVL_IO );
1558
/* Read current GPIO mask and outputs */
1559
linda_readq ( linda, &extctrl, QIB_7220_EXTCtrl_offset );
1560
linda_readq ( linda, &gpioout, QIB_7220_GPIOOut_offset );
1562
/* Update outputs and output enables. I2C lines are tied
1563
* high, so we always set the output to 0 and use the output
1564
* enable to control the line.
1566
output_enables = BIT_GET ( &extctrl, GPIOOe );
1567
output_enables = ( ( output_enables & ~bit ) | ( ~data & bit ) );
1568
outputs = BIT_GET ( &gpioout, GPIO );
1569
outputs = ( outputs & ~bit );
1570
BIT_SET ( &extctrl, GPIOOe, output_enables );
1571
BIT_SET ( &gpioout, GPIO, outputs );
1573
/* Write the output enable first; that way we avoid logic
1576
linda_writeq ( linda, &extctrl, QIB_7220_EXTCtrl_offset );
1577
linda_writeq ( linda, &gpioout, QIB_7220_GPIOOut_offset );
1580
DBG_ENABLE ( DBGLVL_IO );
1583
/** Linda I2C bit-bashing interface operations */
1584
static struct bit_basher_operations linda_i2c_basher_ops = {
1585
.read = linda_i2c_read_bit,
1586
.write = linda_i2c_write_bit,
1590
* Initialise Linda I2C subsystem
1592
* @v linda Linda device
1593
* @ret rc Return status code
1595
static int linda_init_i2c ( struct linda *linda ) {
1596
static int try_eeprom_address[] = { 0x51, 0x50 };
1600
/* Initialise bus */
1601
if ( ( rc = init_i2c_bit_basher ( &linda->i2c,
1602
&linda_i2c_basher_ops ) ) != 0 ) {
1603
DBGC ( linda, "Linda %p could not initialise I2C bus: %s\n",
1604
linda, strerror ( rc ) );
1608
/* Probe for devices */
1609
for ( i = 0 ; i < ( sizeof ( try_eeprom_address ) /
1610
sizeof ( try_eeprom_address[0] ) ) ; i++ ) {
1611
init_i2c_eeprom ( &linda->eeprom, try_eeprom_address[i] );
1612
if ( ( rc = i2c_check_presence ( &linda->i2c.i2c,
1613
&linda->eeprom ) ) == 0 ) {
1614
DBGC2 ( linda, "Linda %p found EEPROM at %02x\n",
1615
linda, try_eeprom_address[i] );
1620
DBGC ( linda, "Linda %p could not find EEPROM\n", linda );
1625
* Read EEPROM parameters
1627
* @v linda Linda device
1628
* @v guid GUID to fill in
1629
* @ret rc Return status code
1631
static int linda_read_eeprom ( struct linda *linda, union ib_guid *guid ) {
1632
struct i2c_interface *i2c = &linda->i2c.i2c;
1636
if ( ( rc = i2c->read ( i2c, &linda->eeprom, LINDA_EEPROM_GUID_OFFSET,
1637
guid->bytes, sizeof ( *guid ) ) ) != 0 ) {
1638
DBGC ( linda, "Linda %p could not read GUID: %s\n",
1639
linda, strerror ( rc ) );
1642
DBGC2 ( linda, "Linda %p has GUID " IB_GUID_FMT "\n",
1643
linda, IB_GUID_ARGS ( guid ) );
1645
/* Read serial number (debug only) */
1647
uint8_t serial[LINDA_EEPROM_SERIAL_SIZE + 1];
1649
serial[ sizeof ( serial ) - 1 ] = '\0';
1650
if ( ( rc = i2c->read ( i2c, &linda->eeprom,
1651
LINDA_EEPROM_SERIAL_OFFSET, serial,
1652
( sizeof ( serial ) - 1 ) ) ) != 0 ) {
1653
DBGC ( linda, "Linda %p could not read serial: %s\n",
1654
linda, strerror ( rc ) );
1657
DBGC2 ( linda, "Linda %p has serial number \"%s\"\n",
1664
/***************************************************************************
1666
* External parallel bus access
1668
***************************************************************************
1672
* Request ownership of the IB external parallel bus
1674
* @v linda Linda device
1675
* @ret rc Return status code
1677
static int linda_ib_epb_request ( struct linda *linda ) {
1678
struct QIB_7220_ibsd_epb_access_ctrl access;
1681
/* Request ownership */
1682
memset ( &access, 0, sizeof ( access ) );
1683
BIT_FILL_1 ( &access, sw_ib_epb_req, 1 );
1684
linda_writeq ( linda, &access, QIB_7220_ibsd_epb_access_ctrl_offset );
1686
/* Wait for ownership to be granted */
1687
for ( i = 0 ; i < LINDA_EPB_REQUEST_MAX_WAIT_US ; i++ ) {
1688
linda_readq ( linda, &access,
1689
QIB_7220_ibsd_epb_access_ctrl_offset );
1690
if ( BIT_GET ( &access, sw_ib_epb_req_granted ) )
1695
DBGC ( linda, "Linda %p timed out waiting for IB EPB request\n",
1701
* Wait for IB external parallel bus transaction to complete
1703
* @v linda Linda device
1704
* @v xact Buffer to hold transaction result
1705
* @ret rc Return status code
1707
static int linda_ib_epb_wait ( struct linda *linda,
1708
struct QIB_7220_ibsd_epb_transaction_reg *xact ) {
1711
/* Discard first read to allow for signals crossing clock domains */
1712
linda_readq ( linda, xact, QIB_7220_ibsd_epb_transaction_reg_offset );
1714
for ( i = 0 ; i < LINDA_EPB_XACT_MAX_WAIT_US ; i++ ) {
1715
linda_readq ( linda, xact,
1716
QIB_7220_ibsd_epb_transaction_reg_offset );
1717
if ( BIT_GET ( xact, ib_epb_rdy ) ) {
1718
if ( BIT_GET ( xact, ib_epb_req_error ) ) {
1719
DBGC ( linda, "Linda %p EPB transaction "
1720
"failed\n", linda );
1729
DBGC ( linda, "Linda %p timed out waiting for IB EPB transaction\n",
1735
* Release ownership of the IB external parallel bus
1737
* @v linda Linda device
1739
static void linda_ib_epb_release ( struct linda *linda ) {
1740
struct QIB_7220_ibsd_epb_access_ctrl access;
1742
memset ( &access, 0, sizeof ( access ) );
1743
BIT_FILL_1 ( &access, sw_ib_epb_req, 0 );
1744
linda_writeq ( linda, &access, QIB_7220_ibsd_epb_access_ctrl_offset );
1748
* Read data via IB external parallel bus
1750
* @v linda Linda device
1751
* @v location EPB location
1752
* @ret data Data read, or negative error
1754
* You must have already acquired ownership of the IB external
1757
static int linda_ib_epb_read ( struct linda *linda, unsigned int location ) {
1758
struct QIB_7220_ibsd_epb_transaction_reg xact;
1762
/* Ensure no transaction is currently in progress */
1763
if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
1767
memset ( &xact, 0, sizeof ( xact ) );
1769
ib_epb_address, LINDA_EPB_LOC_ADDRESS ( location ),
1770
ib_epb_read_write, LINDA_EPB_READ,
1771
ib_epb_cs, LINDA_EPB_LOC_CS ( location ) );
1772
linda_writeq ( linda, &xact,
1773
QIB_7220_ibsd_epb_transaction_reg_offset );
1775
/* Wait for transaction to complete */
1776
if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
1779
data = BIT_GET ( &xact, ib_epb_data );
1784
* Write data via IB external parallel bus
1786
* @v linda Linda device
1787
* @v location EPB location
1788
* @v data Data to write
1789
* @ret rc Return status code
1791
* You must have already acquired ownership of the IB external
1794
static int linda_ib_epb_write ( struct linda *linda, unsigned int location,
1795
unsigned int data ) {
1796
struct QIB_7220_ibsd_epb_transaction_reg xact;
1799
/* Ensure no transaction is currently in progress */
1800
if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
1804
memset ( &xact, 0, sizeof ( xact ) );
1807
ib_epb_address, LINDA_EPB_LOC_ADDRESS ( location ),
1808
ib_epb_read_write, LINDA_EPB_WRITE,
1809
ib_epb_cs, LINDA_EPB_LOC_CS ( location ) );
1810
linda_writeq ( linda, &xact,
1811
QIB_7220_ibsd_epb_transaction_reg_offset );
1813
/* Wait for transaction to complete */
1814
if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
1821
* Read/modify/write EPB register
1823
* @v linda Linda device
1825
* @v channel Channel
1826
* @v element Element
1828
* @v value Value to set
1829
* @v mask Mask to apply to old value
1830
* @ret rc Return status code
1832
static int linda_ib_epb_mod_reg ( struct linda *linda, unsigned int cs,
1833
unsigned int channel, unsigned int element,
1834
unsigned int reg, unsigned int value,
1835
unsigned int mask ) {
1836
unsigned int location;
1840
DBG_DISABLE ( DBGLVL_IO );
1843
assert ( ( value & mask ) == value );
1845
/* Acquire bus ownership */
1846
if ( ( rc = linda_ib_epb_request ( linda ) ) != 0 )
1849
/* Read existing value, if necessary */
1850
location = LINDA_EPB_LOC ( cs, channel, element, reg );
1851
if ( (~mask) & 0xff ) {
1852
old_value = linda_ib_epb_read ( linda, location );
1853
if ( old_value < 0 ) {
1862
value = ( ( old_value & ~mask ) | value );
1863
DBGCP ( linda, "Linda %p CS %d EPB(%d,%d,%#02x) %#02x => %#02x\n",
1864
linda, cs, channel, element, reg, old_value, value );
1865
if ( ( rc = linda_ib_epb_write ( linda, location, value ) ) != 0 )
1870
linda_ib_epb_release ( linda );
1872
DBG_ENABLE ( DBGLVL_IO );
1877
* Transfer data to/from microcontroller RAM
1879
* @v linda Linda device
1880
* @v address Starting address
1881
* @v write Data to write, or NULL
1882
* @v read Data to read, or NULL
1883
* @v len Length of data
1884
* @ret rc Return status code
1886
static int linda_ib_epb_ram_xfer ( struct linda *linda, unsigned int address,
1887
const void *write, void *read,
1889
unsigned int control;
1890
unsigned int address_hi;
1891
unsigned int address_lo;
1895
DBG_DISABLE ( DBGLVL_IO );
1897
assert ( ! ( write && read ) );
1898
assert ( ( address % LINDA_EPB_UC_CHUNK_SIZE ) == 0 );
1899
assert ( ( len % LINDA_EPB_UC_CHUNK_SIZE ) == 0 );
1901
/* Acquire bus ownership */
1902
if ( ( rc = linda_ib_epb_request ( linda ) ) != 0 )
1908
/* Reset the address for each new chunk */
1909
if ( ( address % LINDA_EPB_UC_CHUNK_SIZE ) == 0 ) {
1911
/* Write the control register */
1912
control = ( read ? LINDA_EPB_UC_CTL_READ :
1913
LINDA_EPB_UC_CTL_WRITE );
1914
if ( ( rc = linda_ib_epb_write ( linda,
1919
/* Write the address registers */
1920
address_hi = ( address >> 8 );
1921
if ( ( rc = linda_ib_epb_write ( linda,
1922
LINDA_EPB_UC_ADDR_HI,
1923
address_hi ) ) != 0 )
1925
address_lo = ( address & 0xff );
1926
if ( ( rc = linda_ib_epb_write ( linda,
1927
LINDA_EPB_UC_ADDR_LO,
1928
address_lo ) ) != 0 )
1932
/* Read or write the data */
1934
data = linda_ib_epb_read ( linda, LINDA_EPB_UC_DATA );
1939
*( ( uint8_t * ) read++ ) = data;
1941
data = *( ( uint8_t * ) write++ );
1942
if ( ( rc = linda_ib_epb_write ( linda,
1950
/* Reset the control byte after each chunk */
1951
if ( ( address % LINDA_EPB_UC_CHUNK_SIZE ) == 0 ) {
1952
if ( ( rc = linda_ib_epb_write ( linda,
1960
linda_ib_epb_release ( linda );
1963
DBG_ENABLE ( DBGLVL_IO );
1967
/***************************************************************************
1969
* Infiniband SerDes initialisation
1971
***************************************************************************
1974
/** A Linda SerDes parameter */
1975
struct linda_serdes_param {
1976
/** EPB address as constructed by LINDA_EPB_ADDRESS() */
1980
/** Mask to apply to old value */
1984
/** Magic "all channels" channel number */
1985
#define LINDA_EPB_ALL_CHANNELS 31
1987
/** End of SerDes parameter list marker */
1988
#define LINDA_SERDES_PARAM_END { 0, 0, 0 }
1991
* Program IB SerDes register(s)
1993
* @v linda Linda device
1994
* @v param SerDes parameter
1995
* @ret rc Return status code
1997
static int linda_set_serdes_param ( struct linda *linda,
1998
struct linda_serdes_param *param ) {
1999
unsigned int channel;
2000
unsigned int channel_start;
2001
unsigned int channel_end;
2002
unsigned int element;
2006
/* Break down the EPB address and determine channels */
2007
channel = LINDA_EPB_ADDRESS_CHANNEL ( param->address );
2008
element = LINDA_EPB_ADDRESS_ELEMENT ( param->address );
2009
reg = LINDA_EPB_ADDRESS_REG ( param->address );
2010
if ( channel == LINDA_EPB_ALL_CHANNELS ) {
2014
channel_start = channel_end = channel;
2017
/* Modify register for each specified channel */
2018
for ( channel = channel_start ; channel <= channel_end ; channel++ ) {
2019
if ( ( rc = linda_ib_epb_mod_reg ( linda, LINDA_EPB_CS_SERDES,
2020
channel, element, reg,
2022
param->mask ) ) != 0 )
2030
* Program IB SerDes registers
2032
* @v linda Linda device
2033
* @v param SerDes parameters
2034
* @v count Number of parameters
2035
* @ret rc Return status code
2037
static int linda_set_serdes_params ( struct linda *linda,
2038
struct linda_serdes_param *params ) {
2041
for ( ; params->mask != 0 ; params++ ){
2042
if ( ( rc = linda_set_serdes_param ( linda,
2050
#define LINDA_DDS_VAL( amp_d, main_d, ipst_d, ipre_d, \
2051
amp_s, main_s, ipst_s, ipre_s ) \
2052
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x00 ), \
2053
( ( ( amp_d & 0x1f ) << 1 ) | 1 ), 0xff }, \
2054
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x01 ), \
2055
( ( ( amp_s & 0x1f ) << 1 ) | 1 ), 0xff }, \
2056
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x09 ), \
2057
( ( main_d << 3 ) | 4 | ( ipre_d >> 2 ) ), 0xff }, \
2058
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x0a ), \
2059
( ( main_s << 3 ) | 4 | ( ipre_s >> 2 ) ), 0xff }, \
2060
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x06 ), \
2061
( ( ( ipst_d & 0xf ) << 1 ) | \
2062
( ( ipre_d & 3 ) << 6 ) | 0x21 ), 0xff }, \
2063
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x07 ), \
2064
( ( ( ipst_s & 0xf ) << 1 ) | \
2065
( ( ipre_s & 3 ) << 6) | 0x21 ), 0xff }
2068
* Linda SerDes default parameters
2070
* These magic start-of-day values are taken from the Linux driver.
2072
static struct linda_serdes_param linda_serdes_defaults1[] = {
2074
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x00 ), 0xd4, 0xff },
2076
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x05 ), 0x2d, 0xff },
2078
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x08 ), 0x03, 0x0f },
2080
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x27 ), 0x10, 0xff },
2082
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x28 ), 0x30, 0xff },
2084
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x0e ), 0x40, 0xff },
2086
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x06 ), 0x04, 0xff },
2088
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x0f ), 0x04, 0xff },
2089
/* End of this block */
2090
LINDA_SERDES_PARAM_END
2092
static struct linda_serdes_param linda_serdes_defaults2[] = {
2094
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x06 ), 0x00, 0xff },
2096
LINDA_DDS_VAL ( 31, 19, 12, 0, 29, 22, 9, 0 ),
2097
/* Set Rcv Eq. to Preset node */
2098
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x27 ), 0x10, 0xff },
2100
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x08 ), 0x00, 0xff },
2102
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x21 ), 0x00, 0xff },
2104
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x09 ), 0x02, 0xff },
2106
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x23 ), 0x02, 0xff },
2108
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1b ), 0x0c, 0xff },
2110
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1c ), 0x0c, 0xff },
2112
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1e ), 0x10, 0xff },
2114
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1f ), 0x10, 0xff },
2115
/* VCDL_CTRL0 toggle */
2116
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x06 ), 0x20, 0xff },
2117
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x06 ), 0x00, 0xff },
2119
{ LINDA_EPB_ADDRESS ( 7, 0, 0x15 ), 0x80, 0xff },
2120
/* End of this block */
2121
LINDA_SERDES_PARAM_END
2123
static struct linda_serdes_param linda_serdes_defaults3[] = {
2125
{ LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x27 ), 0x00, 0x38 },
2126
/* End of this block */
2127
LINDA_SERDES_PARAM_END
2131
* Program the microcontroller RAM
2133
* @v linda Linda device
2134
* @ret rc Return status code
2136
static int linda_program_uc_ram ( struct linda *linda ) {
2139
if ( ( rc = linda_ib_epb_ram_xfer ( linda, 0, linda_ib_fw, NULL,
2140
sizeof ( linda_ib_fw ) ) ) != 0 ){
2141
DBGC ( linda, "Linda %p could not load IB firmware: %s\n",
2142
linda, strerror ( rc ) );
2150
* Verify the microcontroller RAM
2152
* @v linda Linda device
2153
* @ret rc Return status code
2155
static int linda_verify_uc_ram ( struct linda *linda ) {
2156
uint8_t verify[LINDA_EPB_UC_CHUNK_SIZE];
2157
unsigned int offset;
2160
for ( offset = 0 ; offset < sizeof ( linda_ib_fw );
2161
offset += sizeof ( verify ) ) {
2162
if ( ( rc = linda_ib_epb_ram_xfer ( linda, offset,
2164
sizeof (verify) )) != 0 ){
2165
DBGC ( linda, "Linda %p could not read back IB "
2166
"firmware: %s\n", linda, strerror ( rc ) );
2169
if ( memcmp ( ( linda_ib_fw + offset ), verify,
2170
sizeof ( verify ) ) != 0 ) {
2171
DBGC ( linda, "Linda %p firmware verification failed "
2172
"at offset %#x\n", linda, offset );
2173
DBGC_HDA ( linda, offset, ( linda_ib_fw + offset ),
2174
sizeof ( verify ) );
2175
DBGC_HDA ( linda, offset, verify, sizeof ( verify ) );
2180
DBGC2 ( linda, "Linda %p firmware verified ok\n", linda );
2185
* Use the microcontroller to trim the IB link
2187
* @v linda Linda device
2188
* @ret rc Return status code
2190
static int linda_trim_ib ( struct linda *linda ) {
2191
struct QIB_7220_IBSerDesCtrl ctrl;
2192
struct QIB_7220_IntStatus intstatus;
2196
/* Bring the microcontroller out of reset */
2197
linda_readq ( linda, &ctrl, QIB_7220_IBSerDesCtrl_offset );
2198
BIT_SET ( &ctrl, ResetIB_uC_Core, 0 );
2199
linda_writeq ( linda, &ctrl, QIB_7220_IBSerDesCtrl_offset );
2201
/* Wait for the "trim done" signal */
2202
for ( i = 0 ; i < LINDA_TRIM_DONE_MAX_WAIT_MS ; i++ ) {
2203
linda_readq ( linda, &intstatus, QIB_7220_IntStatus_offset );
2204
if ( BIT_GET ( &intstatus, IBSerdesTrimDone ) ) {
2211
DBGC ( linda, "Linda %p timed out waiting for trim done\n", linda );
2214
/* Put the microcontroller back into reset */
2215
BIT_SET ( &ctrl, ResetIB_uC_Core, 1 );
2216
linda_writeq ( linda, &ctrl, QIB_7220_IBSerDesCtrl_offset );
2222
* Initialise the IB SerDes
2224
* @v linda Linda device
2225
* @ret rc Return status code
2227
static int linda_init_ib_serdes ( struct linda *linda ) {
2228
struct QIB_7220_Control control;
2229
struct QIB_7220_IBCCtrl ibcctrl;
2230
struct QIB_7220_IBCDDRCtrl ibcddrctrl;
2231
struct QIB_7220_XGXSCfg xgxscfg;
2235
linda_readq ( linda, &control, QIB_7220_Control_offset );
2236
BIT_SET ( &control, LinkEn, 0 );
2237
linda_writeq ( linda, &control, QIB_7220_Control_offset );
2239
/* Configure sensible defaults for IBC */
2240
memset ( &ibcctrl, 0, sizeof ( ibcctrl ) );
2241
BIT_FILL_6 ( &ibcctrl, /* Tuning values taken from Linux driver */
2242
FlowCtrlPeriod, 0x03,
2243
FlowCtrlWaterMark, 0x05,
2244
MaxPktLen, ( ( LINDA_RECV_HEADER_SIZE +
2245
LINDA_RECV_PAYLOAD_SIZE +
2246
4 /* ICRC */ ) >> 2 ),
2247
PhyerrThreshold, 0xf,
2248
OverrunThreshold, 0xf,
2250
linda_writeq ( linda, &ibcctrl, QIB_7220_IBCCtrl_offset );
2252
/* Force SDR only to avoid needing all the DDR tuning,
2253
* Mellanox compatibility hacks etc. SDR is plenty for
2254
* boot-time operation.
2256
linda_readq ( linda, &ibcddrctrl, QIB_7220_IBCDDRCtrl_offset );
2257
BIT_SET ( &ibcddrctrl, IB_ENHANCED_MODE, 0 );
2258
BIT_SET ( &ibcddrctrl, SD_SPEED_SDR, 1 );
2259
BIT_SET ( &ibcddrctrl, SD_SPEED_DDR, 0 );
2260
BIT_SET ( &ibcddrctrl, SD_SPEED_QDR, 0 );
2261
BIT_SET ( &ibcddrctrl, HRTBT_ENB, 0 );
2262
BIT_SET ( &ibcddrctrl, HRTBT_AUTO, 0 );
2263
linda_writeq ( linda, &ibcddrctrl, QIB_7220_IBCDDRCtrl_offset );
2265
/* Set default SerDes parameters */
2266
if ( ( rc = linda_set_serdes_params ( linda,
2267
linda_serdes_defaults1 ) ) != 0 )
2269
udelay ( 415 ); /* Magic delay while SerDes sorts itself out */
2270
if ( ( rc = linda_set_serdes_params ( linda,
2271
linda_serdes_defaults2 ) ) != 0 )
2274
/* Program the microcontroller RAM */
2275
if ( ( rc = linda_program_uc_ram ( linda ) ) != 0 )
2278
/* Verify the microcontroller RAM contents */
2280
if ( ( rc = linda_verify_uc_ram ( linda ) ) != 0 )
2284
/* More SerDes tuning */
2285
if ( ( rc = linda_set_serdes_params ( linda,
2286
linda_serdes_defaults3 ) ) != 0 )
2289
/* Use the microcontroller to trim the IB link */
2290
if ( ( rc = linda_trim_ib ( linda ) ) != 0 )
2293
/* Bring XGXS out of reset */
2294
linda_readq ( linda, &xgxscfg, QIB_7220_XGXSCfg_offset );
2295
BIT_SET ( &xgxscfg, tx_rx_reset, 0 );
2296
BIT_SET ( &xgxscfg, xcv_reset, 0 );
2297
linda_writeq ( linda, &xgxscfg, QIB_7220_XGXSCfg_offset );
2302
/***************************************************************************
2304
* PCI layer interface
2306
***************************************************************************
2314
* @ret rc Return status code
2316
static int linda_probe ( struct pci_device *pci ) {
2317
struct ib_device *ibdev;
2318
struct linda *linda;
2319
struct QIB_7220_Revision revision;
2322
/* Allocate Infiniband device */
2323
ibdev = alloc_ibdev ( sizeof ( *linda ) );
2326
goto err_alloc_ibdev;
2328
pci_set_drvdata ( pci, ibdev );
2329
linda = ib_get_drvdata ( ibdev );
2330
ibdev->op = &linda_ib_operations;
2331
ibdev->dev = &pci->dev;
2334
/* Fix up PCI device */
2335
adjust_pci_device ( pci );
2338
linda->regs = ioremap ( pci->membase, LINDA_BAR0_SIZE );
2339
DBGC2 ( linda, "Linda %p has BAR at %08lx\n", linda, pci->membase );
2341
/* Print some general data */
2342
linda_readq ( linda, &revision, QIB_7220_Revision_offset );
2343
DBGC2 ( linda, "Linda %p board %02lx v%ld.%ld.%ld.%ld\n", linda,
2344
BIT_GET ( &revision, BoardID ),
2345
BIT_GET ( &revision, R_SW ),
2346
BIT_GET ( &revision, R_Arch ),
2347
BIT_GET ( &revision, R_ChipRevMajor ),
2348
BIT_GET ( &revision, R_ChipRevMinor ) );
2350
/* Record link capabilities. Note that we force SDR only to
2351
* avoid having to carry extra code for DDR tuning etc.
2353
ibdev->link_width_enabled = ibdev->link_width_supported =
2354
( IB_LINK_WIDTH_4X | IB_LINK_WIDTH_1X );
2355
ibdev->link_speed_enabled = ibdev->link_speed_supported =
2358
/* Initialise I2C subsystem */
2359
if ( ( rc = linda_init_i2c ( linda ) ) != 0 )
2362
/* Read EEPROM parameters */
2363
if ( ( rc = linda_read_eeprom ( linda, &ibdev->node_guid ) ) != 0 )
2364
goto err_read_eeprom;
2365
memcpy ( &ibdev->gid.s.guid, &ibdev->node_guid,
2366
sizeof ( ibdev->gid.s.guid ) );
2368
/* Initialise send datapath */
2369
if ( ( rc = linda_init_send ( linda ) ) != 0 )
2372
/* Initialise receive datapath */
2373
if ( ( rc = linda_init_recv ( linda ) ) != 0 )
2376
/* Initialise the IB SerDes */
2377
if ( ( rc = linda_init_ib_serdes ( linda ) ) != 0 )
2378
goto err_init_ib_serdes;
2380
/* Register Infiniband device */
2381
if ( ( rc = register_ibdev ( ibdev ) ) != 0 ) {
2382
DBGC ( linda, "Linda %p could not register IB "
2383
"device: %s\n", linda, strerror ( rc ) );
2384
goto err_register_ibdev;
2389
unregister_ibdev ( ibdev );
2391
linda_fini_recv ( linda );
2393
linda_fini_send ( linda );
2398
iounmap ( linda->regs );
2399
ibdev_put ( ibdev );
2409
static void linda_remove ( struct pci_device *pci ) {
2410
struct ib_device *ibdev = pci_get_drvdata ( pci );
2411
struct linda *linda = ib_get_drvdata ( ibdev );
2413
unregister_ibdev ( ibdev );
2414
linda_fini_recv ( linda );
2415
linda_fini_send ( linda );
2416
iounmap ( linda->regs );
2417
ibdev_put ( ibdev );
2420
static struct pci_device_id linda_nics[] = {
2421
PCI_ROM ( 0x1077, 0x7220, "iba7220", "QLE7240/7280 HCA driver", 0 ),
2424
struct pci_driver linda_driver __pci_driver = {
2426
.id_count = ( sizeof ( linda_nics ) / sizeof ( linda_nics[0] ) ),
2427
.probe = linda_probe,
2428
.remove = linda_remove,