iPXE
linda.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
3 *
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.
8 *
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.
13 *
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
17 * 02110-1301, USA.
18 *
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.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26#include <stdint.h>
27#include <stdlib.h>
28#include <string.h>
29#include <errno.h>
30#include <unistd.h>
31#include <assert.h>
32#include <ipxe/io.h>
33#include <ipxe/pci.h>
34#include <ipxe/infiniband.h>
35#include <ipxe/i2c.h>
36#include <ipxe/bitbash.h>
37#include <ipxe/malloc.h>
38#include <ipxe/iobuf.h>
39#include "linda.h"
40
41/**
42 * @file
43 *
44 * QLogic Linda Infiniband HCA
45 *
46 */
47
48/** A Linda send work queue */
50 /** Send buffer usage */
52 /** Producer index */
53 unsigned int prod;
54 /** Consumer index */
55 unsigned int cons;
56};
57
58/** A Linda receive work queue */
60 /** Receive header ring */
61 void *header;
62 /** Receive header producer offset (written by hardware) */
64 /** Receive header consumer offset */
65 unsigned int header_cons;
66 /** Offset within register space of the eager array */
67 unsigned long eager_array;
68 /** Number of entries in eager array */
69 unsigned int eager_entries;
70 /** Eager array producer index */
71 unsigned int eager_prod;
72 /** Eager array consumer index */
73 unsigned int eager_cons;
74};
75
76/** A Linda HCA */
77struct linda {
78 /** Registers */
79 void *regs;
80
81 /** In-use contexts */
83 /** Send work queues */
85 /** Receive work queues */
87
88 /** Offset within register space of the first send buffer */
89 unsigned long send_buffer_base;
90 /** Send buffer availability (reported by hardware) */
92 /** Send buffer availability (maintained by software) */
94 /** Send buffer availability producer counter */
95 unsigned int send_buf_prod;
96 /** Send buffer availability consumer counter */
97 unsigned int send_buf_cons;
98 /** Number of reserved send buffers (across all QPs) */
99 unsigned int reserved_send_bufs;
100
101 /** I2C bit-bashing interface */
103 /** I2C serial EEPROM */
105};
106
107/***************************************************************************
108 *
109 * Linda register access
110 *
111 ***************************************************************************
112 *
113 * This card requires atomic 64-bit accesses. Strange things happen
114 * if you try to use 32-bit accesses; sometimes they work, sometimes
115 * they don't, sometimes you get random data.
116 */
117
118/**
119 * Read Linda qword register
120 *
121 * @v linda Linda device
122 * @v qword Register buffer to read into
123 * @v offset Register offset
124 */
125static void linda_readq ( struct linda *linda, uint64_t *qword,
126 unsigned long offset ) {
127 *qword = readq ( linda->regs + offset );
128}
129#define linda_readq( _linda, _ptr, _offset ) \
130 linda_readq ( (_linda), (_ptr)->u.qwords, (_offset) )
131#define linda_readq_array8b( _linda, _ptr, _offset, _idx ) \
132 linda_readq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) )
133#define linda_readq_array64k( _linda, _ptr, _offset, _idx ) \
134 linda_readq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 65536 ) ) )
135
136/**
137 * Write Linda qword register
138 *
139 * @v linda Linda device
140 * @v qword Register buffer to write
141 * @v offset Register offset
142 */
143static void linda_writeq ( struct linda *linda, const uint64_t *qword,
144 unsigned long offset ) {
145 writeq ( *qword, ( linda->regs + offset ) );
146}
147#define linda_writeq( _linda, _ptr, _offset ) \
148 linda_writeq ( (_linda), (_ptr)->u.qwords, (_offset) )
149#define linda_writeq_array8b( _linda, _ptr, _offset, _idx ) \
150 linda_writeq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) )
151#define linda_writeq_array64k( _linda, _ptr, _offset, _idx ) \
152 linda_writeq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 65536 ) ) )
153
154/**
155 * Write Linda dword register
156 *
157 * @v linda Linda device
158 * @v dword Value to write
159 * @v offset Register offset
160 */
161static void linda_writel ( struct linda *linda, uint32_t dword,
162 unsigned long offset ) {
163 writel ( dword, ( linda->regs + offset ) );
164}
165
166/***************************************************************************
167 *
168 * Link state management
169 *
170 ***************************************************************************
171 */
172
173/**
174 * Textual representation of link state
175 *
176 * @v link_state Link state
177 * @ret link_text Link state text
178 */
179static const char * linda_link_state_text ( unsigned int link_state ) {
180 switch ( link_state ) {
181 case LINDA_LINK_STATE_DOWN: return "DOWN";
182 case LINDA_LINK_STATE_INIT: return "INIT";
183 case LINDA_LINK_STATE_ARM: return "ARM";
184 case LINDA_LINK_STATE_ACTIVE: return "ACTIVE";
185 case LINDA_LINK_STATE_ACT_DEFER:return "ACT_DEFER";
186 default: return "UNKNOWN";
187 }
188}
189
190/**
191 * Handle link state change
192 *
193 * @v linda Linda device
194 */
195static void linda_link_state_changed ( struct ib_device *ibdev ) {
196 struct linda *linda = ib_get_drvdata ( ibdev );
197 struct QIB_7220_IBCStatus ibcstatus;
198 struct QIB_7220_EXTCtrl extctrl;
199 unsigned int link_state;
200 unsigned int link_width;
201 unsigned int link_speed;
202
203 /* Read link state */
205 link_state = BIT_GET ( &ibcstatus, LinkState );
206 link_width = BIT_GET ( &ibcstatus, LinkWidthActive );
207 link_speed = BIT_GET ( &ibcstatus, LinkSpeedActive );
208 DBGC ( linda, "Linda %p link state %s (%s %s)\n", linda,
209 linda_link_state_text ( link_state ),
210 ( link_speed ? "DDR" : "SDR" ), ( link_width ? "x4" : "x1" ) );
211
212 /* Set LEDs according to link state */
214 BIT_SET ( &extctrl, LEDPriPortGreenOn,
215 ( ( link_state >= LINDA_LINK_STATE_INIT ) ? 1 : 0 ) );
216 BIT_SET ( &extctrl, LEDPriPortYellowOn,
217 ( ( link_state >= LINDA_LINK_STATE_ACTIVE ) ? 1 : 0 ) );
219
220 /* Notify Infiniband core of link state change */
221 ibdev->port_state = ( link_state + 1 );
222 ibdev->link_width_active =
223 ( link_width ? IB_LINK_WIDTH_4X : IB_LINK_WIDTH_1X );
224 ibdev->link_speed_active =
225 ( link_speed ? IB_LINK_SPEED_DDR : IB_LINK_SPEED_SDR );
226 ib_link_state_changed ( ibdev );
227}
228
229/**
230 * Wait for link state change to take effect
231 *
232 * @v linda Linda device
233 * @v new_link_state Expected link state
234 * @ret rc Return status code
235 */
236static int linda_link_state_check ( struct linda *linda,
237 unsigned int new_link_state ) {
238 struct QIB_7220_IBCStatus ibcstatus;
239 unsigned int link_state;
240 unsigned int i;
241
242 for ( i = 0 ; i < LINDA_LINK_STATE_MAX_WAIT_US ; i++ ) {
244 link_state = BIT_GET ( &ibcstatus, LinkState );
245 if ( link_state == new_link_state )
246 return 0;
247 udelay ( 1 );
248 }
249
250 DBGC ( linda, "Linda %p timed out waiting for link state %s\n",
251 linda, linda_link_state_text ( link_state ) );
252 return -ETIMEDOUT;
253}
254
255/**
256 * Set port information
257 *
258 * @v ibdev Infiniband device
259 * @v mad Set port information MAD
260 */
261static int linda_set_port_info ( struct ib_device *ibdev, union ib_mad *mad ) {
262 struct linda *linda = ib_get_drvdata ( ibdev );
263 struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
264 struct QIB_7220_IBCCtrl ibcctrl;
265 unsigned int port_state;
266 unsigned int link_state;
267
268 /* Set new link state */
269 port_state = ( port_info->link_speed_supported__port_state & 0xf );
270 if ( port_state ) {
271 link_state = ( port_state - 1 );
272 DBGC ( linda, "Linda %p set link state to %s (%x)\n", linda,
273 linda_link_state_text ( link_state ), link_state );
275 BIT_SET ( &ibcctrl, LinkCmd, link_state );
277
278 /* Wait for link state change to take effect. Ignore
279 * errors; the current link state will be returned via
280 * the GetResponse MAD.
281 */
282 linda_link_state_check ( linda, link_state );
283 }
284
285 /* Detect and report link state change */
286 linda_link_state_changed ( ibdev );
287
288 return 0;
289}
290
291/**
292 * Set partition key table
293 *
294 * @v ibdev Infiniband device
295 * @v mad Set partition key table MAD
296 */
297static int linda_set_pkey_table ( struct ib_device *ibdev __unused,
298 union ib_mad *mad __unused ) {
299 /* Nothing to do */
300 return 0;
301}
302
303/***************************************************************************
304 *
305 * Context allocation
306 *
307 ***************************************************************************
308 */
309
310/**
311 * Map context number to QPN
312 *
313 * @v ctx Context index
314 * @ret qpn Queue pair number
315 */
316static int linda_ctx_to_qpn ( unsigned int ctx ) {
317 /* This mapping is fixed by hardware */
318 return ( ctx * 2 );
319}
320
321/**
322 * Map QPN to context number
323 *
324 * @v qpn Queue pair number
325 * @ret ctx Context index
326 */
327static int linda_qpn_to_ctx ( unsigned int qpn ) {
328 /* This mapping is fixed by hardware */
329 return ( qpn / 2 );
330}
331
332/**
333 * Allocate a context
334 *
335 * @v linda Linda device
336 * @ret ctx Context index, or negative error
337 */
338static int linda_alloc_ctx ( struct linda *linda ) {
339 unsigned int ctx;
340
341 for ( ctx = 0 ; ctx < LINDA_NUM_CONTEXTS ; ctx++ ) {
342
343 if ( ! linda->used_ctx[ctx] ) {
344 linda->used_ctx[ctx ] = 1;
345 DBGC2 ( linda, "Linda %p CTX %d allocated\n",
346 linda, ctx );
347 return ctx;
348 }
349 }
350
351 DBGC ( linda, "Linda %p out of available contexts\n", linda );
352 return -ENOENT;
353}
354
355/**
356 * Free a context
357 *
358 * @v linda Linda device
359 * @v ctx Context index
360 */
361static void linda_free_ctx ( struct linda *linda, unsigned int ctx ) {
362
363 linda->used_ctx[ctx] = 0;
364 DBGC2 ( linda, "Linda %p CTX %d freed\n", linda, ctx );
365}
366
367/***************************************************************************
368 *
369 * Send datapath
370 *
371 ***************************************************************************
372 */
373
374/** Send buffer toggle bit
375 *
376 * We encode send buffers as 7 bits of send buffer index plus a single
377 * bit which should match the "check" bit in the SendBufAvail array.
378 */
379#define LINDA_SEND_BUF_TOGGLE 0x80
380
381/**
382 * Allocate a send buffer
383 *
384 * @v linda Linda device
385 * @ret send_buf Send buffer
386 *
387 * You must guarantee that a send buffer is available. This is done
388 * by refusing to allocate more TX WQEs in total than the number of
389 * available send buffers.
390 */
391static unsigned int linda_alloc_send_buf ( struct linda *linda ) {
392 unsigned int send_buf;
393
394 send_buf = linda->send_buf[linda->send_buf_cons];
395 send_buf ^= LINDA_SEND_BUF_TOGGLE;
396 linda->send_buf_cons = ( ( linda->send_buf_cons + 1 ) %
398 return send_buf;
399}
400
401/**
402 * Free a send buffer
403 *
404 * @v linda Linda device
405 * @v send_buf Send buffer
406 */
407static void linda_free_send_buf ( struct linda *linda,
408 unsigned int send_buf ) {
409 linda->send_buf[linda->send_buf_prod] = send_buf;
410 linda->send_buf_prod = ( ( linda->send_buf_prod + 1 ) %
412}
413
414/**
415 * Check to see if send buffer is in use
416 *
417 * @v linda Linda device
418 * @v send_buf Send buffer
419 * @ret in_use Send buffer is in use
420 */
421static int linda_send_buf_in_use ( struct linda *linda,
422 unsigned int send_buf ) {
423 unsigned int send_idx;
424 unsigned int send_check;
425 unsigned int inusecheck;
426 unsigned int inuse;
427 unsigned int check;
428
429 send_idx = ( send_buf & ~LINDA_SEND_BUF_TOGGLE );
430 send_check = ( !! ( send_buf & LINDA_SEND_BUF_TOGGLE ) );
431 inusecheck = BIT_GET ( linda->sendbufavail, InUseCheck[send_idx] );
432 inuse = ( !! ( inusecheck & 0x02 ) );
433 check = ( !! ( inusecheck & 0x01 ) );
434 return ( inuse || ( check != send_check ) );
435}
436
437/**
438 * Calculate starting offset for send buffer
439 *
440 * @v linda Linda device
441 * @v send_buf Send buffer
442 * @ret offset Starting offset
443 */
444static unsigned long linda_send_buffer_offset ( struct linda *linda,
445 unsigned int send_buf ) {
446 return ( linda->send_buffer_base +
447 ( ( send_buf & ~LINDA_SEND_BUF_TOGGLE ) *
449}
450
451/**
452 * Create send work queue
453 *
454 * @v linda Linda device
455 * @v qp Queue pair
456 */
457static int linda_create_send_wq ( struct linda *linda,
458 struct ib_queue_pair *qp ) {
459 struct ib_work_queue *wq = &qp->send;
460 struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
461 int rc;
462
463 /* Reserve send buffers */
464 if ( ( linda->reserved_send_bufs + qp->send.num_wqes ) >
466 DBGC ( linda, "Linda %p out of send buffers (have %d, used "
467 "%d, need %d)\n", linda, LINDA_MAX_SEND_BUFS,
468 linda->reserved_send_bufs, qp->send.num_wqes );
469 rc = -ENOBUFS;
470 goto err_reserve_bufs;
471 }
472 linda->reserved_send_bufs += qp->send.num_wqes;
473
474 /* Reset work queue */
475 linda_wq->prod = 0;
476 linda_wq->cons = 0;
477
478 /* Allocate space for send buffer uasge list */
479 linda_wq->send_buf = zalloc ( qp->send.num_wqes *
480 sizeof ( linda_wq->send_buf[0] ) );
481 if ( ! linda_wq->send_buf ) {
482 rc = -ENOBUFS;
483 goto err_alloc_send_buf;
484 }
485
486 return 0;
487
488 free ( linda_wq->send_buf );
489 err_alloc_send_buf:
490 linda->reserved_send_bufs -= qp->send.num_wqes;
491 err_reserve_bufs:
492 return rc;
493}
494
495/**
496 * Destroy send work queue
497 *
498 * @v linda Linda device
499 * @v qp Queue pair
500 */
501static void linda_destroy_send_wq ( struct linda *linda,
502 struct ib_queue_pair *qp ) {
503 struct ib_work_queue *wq = &qp->send;
504 struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
505
506 free ( linda_wq->send_buf );
507 linda->reserved_send_bufs -= qp->send.num_wqes;
508}
509
510/**
511 * Initialise send datapath
512 *
513 * @v linda Linda device
514 * @ret rc Return status code
515 */
516static int linda_init_send ( struct linda *linda ) {
517 struct QIB_7220_SendBufBase sendbufbase;
518 struct QIB_7220_SendBufAvailAddr sendbufavailaddr;
519 struct QIB_7220_SendCtrl sendctrl;
520 unsigned int i;
521 int rc;
522
523 /* Retrieve SendBufBase */
525 linda->send_buffer_base = BIT_GET ( &sendbufbase,
526 BaseAddr_SmallPIO );
527 DBGC ( linda, "Linda %p send buffers at %lx\n",
529
530 /* Initialise the send_buf[] array */
531 for ( i = 0 ; i < LINDA_MAX_SEND_BUFS ; i++ )
532 linda->send_buf[i] = i;
533
534 /* Allocate space for the SendBufAvail array */
537 if ( ! linda->sendbufavail ) {
538 rc = -ENOMEM;
539 goto err_alloc_sendbufavail;
540 }
541 memset ( linda->sendbufavail, 0, sizeof ( *linda->sendbufavail ) );
542
543 /* Program SendBufAvailAddr into the hardware */
544 memset ( &sendbufavailaddr, 0, sizeof ( sendbufavailaddr ) );
545 BIT_FILL_1 ( &sendbufavailaddr, SendBufAvailAddr,
546 ( virt_to_bus ( linda->sendbufavail ) >> 6 ) );
547 linda_writeq ( linda, &sendbufavailaddr,
549
550 /* Enable sending and DMA of SendBufAvail */
551 memset ( &sendctrl, 0, sizeof ( sendctrl ) );
552 BIT_FILL_2 ( &sendctrl,
553 SendBufAvailUpd, 1,
554 SPioEnable, 1 );
556
557 return 0;
558
559 free_phys ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
560 err_alloc_sendbufavail:
561 return rc;
562}
563
564/**
565 * Shut down send datapath
566 *
567 * @v linda Linda device
568 */
569static void linda_fini_send ( struct linda *linda ) {
570 struct QIB_7220_SendCtrl sendctrl;
571
572 /* Disable sending and DMA of SendBufAvail */
573 memset ( &sendctrl, 0, sizeof ( sendctrl ) );
575 mb();
576
577 /* Ensure hardware has seen this disable */
579
580 free_phys ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
581}
582
583/***************************************************************************
584 *
585 * Receive datapath
586 *
587 ***************************************************************************
588 */
589
590/**
591 * Create receive work queue
592 *
593 * @v linda Linda device
594 * @v qp Queue pair
595 * @ret rc Return status code
596 */
597static int linda_create_recv_wq ( struct linda *linda,
598 struct ib_queue_pair *qp ) {
599 struct ib_work_queue *wq = &qp->recv;
600 struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
601 struct QIB_7220_RcvHdrAddr0 rcvhdraddr;
602 struct QIB_7220_RcvHdrTailAddr0 rcvhdrtailaddr;
603 struct QIB_7220_RcvHdrHead0 rcvhdrhead;
604 struct QIB_7220_scalar rcvegrindexhead;
605 struct QIB_7220_RcvCtrl rcvctrl;
606 unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
607 int rc;
608
609 /* Reset context information */
610 memset ( &linda_wq->header_prod, 0,
611 sizeof ( linda_wq->header_prod ) );
612 linda_wq->header_cons = 0;
613 linda_wq->eager_prod = 0;
614 linda_wq->eager_cons = 0;
615
616 /* Allocate receive header buffer */
619 if ( ! linda_wq->header ) {
620 rc = -ENOMEM;
621 goto err_alloc_header;
622 }
623
624 /* Enable context in hardware */
625 memset ( &rcvhdraddr, 0, sizeof ( rcvhdraddr ) );
626 BIT_FILL_1 ( &rcvhdraddr, RcvHdrAddr0,
627 ( virt_to_bus ( linda_wq->header ) >> 2 ) );
628 linda_writeq_array8b ( linda, &rcvhdraddr,
630 memset ( &rcvhdrtailaddr, 0, sizeof ( rcvhdrtailaddr ) );
631 BIT_FILL_1 ( &rcvhdrtailaddr, RcvHdrTailAddr0,
632 ( virt_to_bus ( &linda_wq->header_prod ) >> 2 ) );
633 linda_writeq_array8b ( linda, &rcvhdrtailaddr,
635 memset ( &rcvhdrhead, 0, sizeof ( rcvhdrhead ) );
636 BIT_FILL_1 ( &rcvhdrhead, counter, 1 );
637 linda_writeq_array64k ( linda, &rcvhdrhead,
639 memset ( &rcvegrindexhead, 0, sizeof ( rcvegrindexhead ) );
640 BIT_FILL_1 ( &rcvegrindexhead, Value, 1 );
641 linda_writeq_array64k ( linda, &rcvegrindexhead,
644 BIT_SET ( &rcvctrl, PortEnable[ctx], 1 );
645 BIT_SET ( &rcvctrl, IntrAvail[ctx], 1 );
647
648 DBGC ( linda, "Linda %p QPN %ld CTX %d hdrs [%lx,%lx) prod %lx\n",
649 linda, qp->qpn, ctx, virt_to_bus ( linda_wq->header ),
650 ( virt_to_bus ( linda_wq->header ) + LINDA_RECV_HEADERS_SIZE ),
651 virt_to_bus ( &linda_wq->header_prod ) );
652 return 0;
653
655 err_alloc_header:
656 return rc;
657}
658
659/**
660 * Destroy receive work queue
661 *
662 * @v linda Linda device
663 * @v qp Queue pair
664 */
665static void linda_destroy_recv_wq ( struct linda *linda,
666 struct ib_queue_pair *qp ) {
667 struct ib_work_queue *wq = &qp->recv;
668 struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
669 struct QIB_7220_RcvCtrl rcvctrl;
670 unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
671
672 /* Disable context in hardware */
674 BIT_SET ( &rcvctrl, PortEnable[ctx], 0 );
675 BIT_SET ( &rcvctrl, IntrAvail[ctx], 0 );
677
678 /* Make sure the hardware has seen that the context is disabled */
680 mb();
681
682 /* Free headers ring */
684
685 /* Free context */
687}
688
689/**
690 * Initialise receive datapath
691 *
692 * @v linda Linda device
693 * @ret rc Return status code
694 */
695static int linda_init_recv ( struct linda *linda ) {
696 struct QIB_7220_RcvCtrl rcvctrl;
697 struct QIB_7220_scalar rcvegrbase;
698 struct QIB_7220_scalar rcvhdrentsize;
699 struct QIB_7220_scalar rcvhdrcnt;
700 struct QIB_7220_RcvBTHQP rcvbthqp;
701 unsigned int portcfg;
702 unsigned long egrbase;
703 unsigned int eager_array_size_0;
704 unsigned int eager_array_size_other;
705 unsigned int ctx;
706
707 /* Select configuration based on number of contexts */
708 switch ( LINDA_NUM_CONTEXTS ) {
709 case 5:
710 portcfg = LINDA_PORTCFG_5CTX;
711 eager_array_size_0 = LINDA_EAGER_ARRAY_SIZE_5CTX_0;
712 eager_array_size_other = LINDA_EAGER_ARRAY_SIZE_5CTX_OTHER;
713 break;
714 case 9:
715 portcfg = LINDA_PORTCFG_9CTX;
716 eager_array_size_0 = LINDA_EAGER_ARRAY_SIZE_9CTX_0;
717 eager_array_size_other = LINDA_EAGER_ARRAY_SIZE_9CTX_OTHER;
718 break;
719 case 17:
720 portcfg = LINDA_PORTCFG_17CTX;
721 eager_array_size_0 = LINDA_EAGER_ARRAY_SIZE_17CTX_0;
722 eager_array_size_other = LINDA_EAGER_ARRAY_SIZE_17CTX_OTHER;
723 break;
724 default:
725 build_assert ( 0 );
726 return -EINVAL;
727 }
728
729 /* Configure number of contexts */
730 memset ( &rcvctrl, 0, sizeof ( rcvctrl ) );
731 BIT_FILL_3 ( &rcvctrl,
732 TailUpd, 1,
733 PortCfg, portcfg,
734 RcvQPMapEnable, 1 );
736
737 /* Configure receive header buffer sizes */
738 memset ( &rcvhdrcnt, 0, sizeof ( rcvhdrcnt ) );
739 BIT_FILL_1 ( &rcvhdrcnt, Value, LINDA_RECV_HEADER_COUNT );
741 memset ( &rcvhdrentsize, 0, sizeof ( rcvhdrentsize ) );
742 BIT_FILL_1 ( &rcvhdrentsize, Value, ( LINDA_RECV_HEADER_SIZE >> 2 ) );
744
745 /* Calculate eager array start addresses for each context */
747 egrbase = BIT_GET ( &rcvegrbase, Value );
748 linda->recv_wq[0].eager_array = egrbase;
749 linda->recv_wq[0].eager_entries = eager_array_size_0;
750 egrbase += ( eager_array_size_0 * sizeof ( struct QIB_7220_RcvEgr ) );
751 for ( ctx = 1 ; ctx < LINDA_NUM_CONTEXTS ; ctx++ ) {
752 linda->recv_wq[ctx].eager_array = egrbase;
753 linda->recv_wq[ctx].eager_entries = eager_array_size_other;
754 egrbase += ( eager_array_size_other *
755 sizeof ( struct QIB_7220_RcvEgr ) );
756 }
757 for ( ctx = 0 ; ctx < LINDA_NUM_CONTEXTS ; ctx++ ) {
758 DBGC ( linda, "Linda %p CTX %d eager array at %lx (%d "
759 "entries)\n", linda, ctx,
762 }
763
764 /* Set the BTH QP for Infinipath packets to an unused value */
765 memset ( &rcvbthqp, 0, sizeof ( rcvbthqp ) );
766 BIT_FILL_1 ( &rcvbthqp, RcvBTHQP, LINDA_QP_IDETH );
768
769 return 0;
770}
771
772/**
773 * Shut down receive datapath
774 *
775 * @v linda Linda device
776 */
777static void linda_fini_recv ( struct linda *linda __unused ) {
778 /* Nothing to do; all contexts were already disabled when the
779 * queue pairs were destroyed
780 */
781}
782
783/***************************************************************************
784 *
785 * Completion queue operations
786 *
787 ***************************************************************************
788 */
789
790/**
791 * Create completion queue
792 *
793 * @v ibdev Infiniband device
794 * @v cq Completion queue
795 * @ret rc Return status code
796 */
797static int linda_create_cq ( struct ib_device *ibdev,
798 struct ib_completion_queue *cq ) {
799 struct linda *linda = ib_get_drvdata ( ibdev );
800 static int cqn;
801
802 /* The hardware has no concept of completion queues. We
803 * simply use the association between CQs and WQs (already
804 * handled by the IB core) to decide which WQs to poll.
805 *
806 * We do set a CQN, just to avoid confusing debug messages
807 * from the IB core.
808 */
809 cq->cqn = ++cqn;
810 DBGC ( linda, "Linda %p CQN %ld created\n", linda, cq->cqn );
811
812 return 0;
813}
814
815/**
816 * Destroy completion queue
817 *
818 * @v ibdev Infiniband device
819 * @v cq Completion queue
820 */
821static void linda_destroy_cq ( struct ib_device *ibdev,
822 struct ib_completion_queue *cq ) {
823 struct linda *linda = ib_get_drvdata ( ibdev );
824
825 /* Nothing to do */
826 DBGC ( linda, "Linda %p CQN %ld destroyed\n", linda, cq->cqn );
827}
828
829/***************************************************************************
830 *
831 * Queue pair operations
832 *
833 ***************************************************************************
834 */
835
836/**
837 * Create queue pair
838 *
839 * @v ibdev Infiniband device
840 * @v qp Queue pair
841 * @ret rc Return status code
842 */
843static int linda_create_qp ( struct ib_device *ibdev,
844 struct ib_queue_pair *qp ) {
845 struct linda *linda = ib_get_drvdata ( ibdev );
846 int ctx;
847 int rc;
848
849 /* Locate an available context */
851 if ( ctx < 0 ) {
852 rc = ctx;
853 goto err_alloc_ctx;
854 }
855
856 /* Set queue pair number based on context index */
857 qp->qpn = linda_ctx_to_qpn ( ctx );
858
859 /* Set work-queue private data pointers */
860 ib_wq_set_drvdata ( &qp->send, &linda->send_wq[ctx] );
861 ib_wq_set_drvdata ( &qp->recv, &linda->recv_wq[ctx] );
862
863 /* Create receive work queue */
864 if ( ( rc = linda_create_recv_wq ( linda, qp ) ) != 0 )
865 goto err_create_recv_wq;
866
867 /* Create send work queue */
868 if ( ( rc = linda_create_send_wq ( linda, qp ) ) != 0 )
869 goto err_create_send_wq;
870
871 return 0;
872
874 err_create_send_wq:
876 err_create_recv_wq:
878 err_alloc_ctx:
879 return rc;
880}
881
882/**
883 * Modify queue pair
884 *
885 * @v ibdev Infiniband device
886 * @v qp Queue pair
887 * @ret rc Return status code
888 */
889static int linda_modify_qp ( struct ib_device *ibdev,
890 struct ib_queue_pair *qp ) {
891 struct linda *linda = ib_get_drvdata ( ibdev );
892
893 /* Nothing to do; the hardware doesn't have a notion of queue
894 * keys
895 */
896 DBGC ( linda, "Linda %p QPN %ld modified\n", linda, qp->qpn );
897 return 0;
898}
899
900/**
901 * Destroy queue pair
902 *
903 * @v ibdev Infiniband device
904 * @v qp Queue pair
905 */
906static void linda_destroy_qp ( struct ib_device *ibdev,
907 struct ib_queue_pair *qp ) {
908 struct linda *linda = ib_get_drvdata ( ibdev );
909
912}
913
914/***************************************************************************
915 *
916 * Work request operations
917 *
918 ***************************************************************************
919 */
920
921/**
922 * Post send work queue entry
923 *
924 * @v ibdev Infiniband device
925 * @v qp Queue pair
926 * @v dest Destination address vector
927 * @v iobuf I/O buffer
928 * @ret rc Return status code
929 */
930static int linda_post_send ( struct ib_device *ibdev,
931 struct ib_queue_pair *qp,
932 struct ib_address_vector *dest,
933 struct io_buffer *iobuf ) {
934 struct linda *linda = ib_get_drvdata ( ibdev );
935 struct ib_work_queue *wq = &qp->send;
936 struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
937 struct QIB_7220_SendPbc sendpbc;
938 uint8_t header_buf[IB_MAX_HEADER_SIZE];
939 struct io_buffer headers;
940 unsigned int send_buf;
941 unsigned long start_offset;
942 unsigned long offset;
943 size_t len;
944 ssize_t frag_len;
945 uint32_t *data;
946
947 /* Allocate send buffer and calculate offset */
948 send_buf = linda_alloc_send_buf ( linda );
949 start_offset = offset = linda_send_buffer_offset ( linda, send_buf );
950
951 /* Store I/O buffer and send buffer index */
952 assert ( wq->iobufs[linda_wq->prod] == NULL );
953 wq->iobufs[linda_wq->prod] = iobuf;
954 linda_wq->send_buf[linda_wq->prod] = send_buf;
955
956 /* Construct headers */
957 iob_populate ( &headers, header_buf, 0, sizeof ( header_buf ) );
958 iob_reserve ( &headers, sizeof ( header_buf ) );
959 ib_push ( ibdev, &headers, qp, iob_len ( iobuf ), dest );
960
961 /* Calculate packet length */
962 len = ( ( sizeof ( sendpbc ) + iob_len ( &headers ) +
963 iob_len ( iobuf ) + 3 ) & ~3 );
964
965 /* Construct send per-buffer control word */
966 memset ( &sendpbc, 0, sizeof ( sendpbc ) );
967 BIT_FILL_2 ( &sendpbc,
968 LengthP1_toibc, ( ( len >> 2 ) - 1 ),
969 VL15, 1 );
970
971 /* Write SendPbc */
973 linda_writeq ( linda, &sendpbc, offset );
974 offset += sizeof ( sendpbc );
975
976 /* Write headers */
977 for ( data = headers.data, frag_len = iob_len ( &headers ) ;
978 frag_len > 0 ; data++, offset += 4, frag_len -= 4 ) {
980 }
981
982 /* Write data */
983 for ( data = iobuf->data, frag_len = iob_len ( iobuf ) ;
984 frag_len > 0 ; data++, offset += 4, frag_len -= 4 ) {
986 }
988
989 assert ( ( start_offset + len ) == offset );
990 DBGC2 ( linda, "Linda %p QPN %ld TX %d(%d) posted [%lx,%lx)\n",
991 linda, qp->qpn, send_buf, linda_wq->prod,
992 start_offset, offset );
993
994 /* Increment producer counter */
995 linda_wq->prod = ( ( linda_wq->prod + 1 ) & ( wq->num_wqes - 1 ) );
996
997 return 0;
998}
999
1000/**
1001 * Complete send work queue entry
1002 *
1003 * @v ibdev Infiniband device
1004 * @v qp Queue pair
1005 * @v wqe_idx Work queue entry index
1006 */
1007static void linda_complete_send ( struct ib_device *ibdev,
1008 struct ib_queue_pair *qp,
1009 unsigned int wqe_idx ) {
1010 struct linda *linda = ib_get_drvdata ( ibdev );
1011 struct ib_work_queue *wq = &qp->send;
1012 struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
1013 struct io_buffer *iobuf;
1014 unsigned int send_buf;
1015
1016 /* Parse completion */
1017 send_buf = linda_wq->send_buf[wqe_idx];
1018 DBGC2 ( linda, "Linda %p QPN %ld TX %d(%d) complete\n",
1019 linda, qp->qpn, send_buf, wqe_idx );
1020
1021 /* Complete work queue entry */
1022 iobuf = wq->iobufs[wqe_idx];
1023 assert ( iobuf != NULL );
1024 ib_complete_send ( ibdev, qp, iobuf, 0 );
1025 wq->iobufs[wqe_idx] = NULL;
1026
1027 /* Free send buffer */
1028 linda_free_send_buf ( linda, send_buf );
1029}
1030
1031/**
1032 * Poll send work queue
1033 *
1034 * @v ibdev Infiniband device
1035 * @v qp Queue pair
1036 */
1037static void linda_poll_send_wq ( struct ib_device *ibdev,
1038 struct ib_queue_pair *qp ) {
1039 struct linda *linda = ib_get_drvdata ( ibdev );
1040 struct ib_work_queue *wq = &qp->send;
1041 struct linda_send_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
1042 unsigned int send_buf;
1043
1044 /* Look for completions */
1045 while ( wq->fill ) {
1046
1047 /* Check to see if send buffer has completed */
1048 send_buf = linda_wq->send_buf[linda_wq->cons];
1050 break;
1051
1052 /* Complete this buffer */
1053 linda_complete_send ( ibdev, qp, linda_wq->cons );
1054
1055 /* Increment consumer counter */
1056 linda_wq->cons = ( ( linda_wq->cons + 1 ) &
1057 ( wq->num_wqes - 1 ) );
1058 }
1059}
1060
1061/**
1062 * Post receive work queue entry
1063 *
1064 * @v ibdev Infiniband device
1065 * @v qp Queue pair
1066 * @v iobuf I/O buffer
1067 * @ret rc Return status code
1068 */
1069static int linda_post_recv ( struct ib_device *ibdev,
1070 struct ib_queue_pair *qp,
1071 struct io_buffer *iobuf ) {
1072 struct linda *linda = ib_get_drvdata ( ibdev );
1073 struct ib_work_queue *wq = &qp->recv;
1074 struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
1075 struct QIB_7220_RcvEgr rcvegr;
1076 struct QIB_7220_scalar rcvegrindexhead;
1077 unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
1079 size_t len;
1080 unsigned int wqe_idx;
1081 unsigned int bufsize;
1082
1083 /* Sanity checks */
1084 addr = virt_to_bus ( iobuf->data );
1085 len = iob_tailroom ( iobuf );
1086 if ( addr & ( LINDA_EAGER_BUFFER_ALIGN - 1 ) ) {
1087 DBGC ( linda, "Linda %p QPN %ld misaligned RX buffer "
1088 "(%08lx)\n", linda, qp->qpn, addr );
1089 return -EINVAL;
1090 }
1091 if ( len != LINDA_RECV_PAYLOAD_SIZE ) {
1092 DBGC ( linda, "Linda %p QPN %ld wrong RX buffer size (%zd)\n",
1093 linda, qp->qpn, len );
1094 return -EINVAL;
1095 }
1096
1097 /* Calculate eager producer index and WQE index */
1098 wqe_idx = ( linda_wq->eager_prod & ( wq->num_wqes - 1 ) );
1099 assert ( wq->iobufs[wqe_idx] == NULL );
1100
1101 /* Store I/O buffer */
1102 wq->iobufs[wqe_idx] = iobuf;
1103
1104 /* Calculate buffer size */
1105 switch ( LINDA_RECV_PAYLOAD_SIZE ) {
1106 case 2048: bufsize = LINDA_EAGER_BUFFER_2K; break;
1107 case 4096: bufsize = LINDA_EAGER_BUFFER_4K; break;
1108 case 8192: bufsize = LINDA_EAGER_BUFFER_8K; break;
1109 case 16384: bufsize = LINDA_EAGER_BUFFER_16K; break;
1110 case 32768: bufsize = LINDA_EAGER_BUFFER_32K; break;
1111 case 65536: bufsize = LINDA_EAGER_BUFFER_64K; break;
1112 default: build_assert ( 0 );
1114 }
1115
1116 /* Post eager buffer */
1117 memset ( &rcvegr, 0, sizeof ( rcvegr ) );
1118 BIT_FILL_2 ( &rcvegr,
1119 Addr, ( addr >> 11 ),
1120 BufSize, bufsize );
1121 linda_writeq_array8b ( linda, &rcvegr,
1122 linda_wq->eager_array, linda_wq->eager_prod );
1123 DBGC2 ( linda, "Linda %p QPN %ld RX egr %d(%d) posted [%lx,%lx)\n",
1124 linda, qp->qpn, linda_wq->eager_prod, wqe_idx,
1125 addr, ( addr + len ) );
1126
1127 /* Increment producer index */
1128 linda_wq->eager_prod = ( ( linda_wq->eager_prod + 1 ) &
1129 ( linda_wq->eager_entries - 1 ) );
1130
1131 /* Update head index */
1132 memset ( &rcvegrindexhead, 0, sizeof ( rcvegrindexhead ) );
1133 BIT_FILL_1 ( &rcvegrindexhead,
1134 Value, ( ( linda_wq->eager_prod + 1 ) &
1135 ( linda_wq->eager_entries - 1 ) ) );
1136 linda_writeq_array64k ( linda, &rcvegrindexhead,
1138
1139 return 0;
1140}
1141
1142/**
1143 * Complete receive work queue entry
1144 *
1145 * @v ibdev Infiniband device
1146 * @v qp Queue pair
1147 * @v header_offs Header offset
1148 */
1149static void linda_complete_recv ( struct ib_device *ibdev,
1150 struct ib_queue_pair *qp,
1151 unsigned int header_offs ) {
1152 struct linda *linda = ib_get_drvdata ( ibdev );
1153 struct ib_work_queue *wq = &qp->recv;
1154 struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
1155 struct QIB_7220_RcvHdrFlags *rcvhdrflags;
1156 struct QIB_7220_RcvEgr rcvegr;
1157 struct io_buffer headers;
1158 struct io_buffer *iobuf;
1159 struct ib_queue_pair *intended_qp;
1160 struct ib_address_vector dest;
1161 struct ib_address_vector source;
1162 unsigned int rcvtype;
1163 unsigned int pktlen;
1164 unsigned int egrindex;
1165 unsigned int useegrbfr;
1166 unsigned int iberr, mkerr, tiderr, khdrerr, mtuerr;
1167 unsigned int lenerr, parityerr, vcrcerr, icrcerr;
1168 unsigned int err;
1169 unsigned int hdrqoffset;
1170 unsigned int header_len;
1171 unsigned int padded_payload_len;
1172 unsigned int wqe_idx;
1173 size_t payload_len;
1174 int qp0;
1175 int rc;
1176
1177 /* RcvHdrFlags are at the end of the header entry */
1178 rcvhdrflags = ( linda_wq->header + header_offs +
1179 LINDA_RECV_HEADER_SIZE - sizeof ( *rcvhdrflags ) );
1180 rcvtype = BIT_GET ( rcvhdrflags, RcvType );
1181 pktlen = ( BIT_GET ( rcvhdrflags, PktLen ) << 2 );
1182 egrindex = BIT_GET ( rcvhdrflags, EgrIndex );
1183 useegrbfr = BIT_GET ( rcvhdrflags, UseEgrBfr );
1184 hdrqoffset = ( BIT_GET ( rcvhdrflags, HdrqOffset ) << 2 );
1185 iberr = BIT_GET ( rcvhdrflags, IBErr );
1186 mkerr = BIT_GET ( rcvhdrflags, MKErr );
1187 tiderr = BIT_GET ( rcvhdrflags, TIDErr );
1188 khdrerr = BIT_GET ( rcvhdrflags, KHdrErr );
1189 mtuerr = BIT_GET ( rcvhdrflags, MTUErr );
1190 lenerr = BIT_GET ( rcvhdrflags, LenErr );
1191 parityerr = BIT_GET ( rcvhdrflags, ParityErr );
1192 vcrcerr = BIT_GET ( rcvhdrflags, VCRCErr );
1193 icrcerr = BIT_GET ( rcvhdrflags, ICRCErr );
1194 header_len = ( LINDA_RECV_HEADER_SIZE - hdrqoffset -
1195 sizeof ( *rcvhdrflags ) );
1196 padded_payload_len = ( pktlen - header_len - 4 /* ICRC */ );
1197 err = ( iberr | mkerr | tiderr | khdrerr | mtuerr |
1198 lenerr | parityerr | vcrcerr | icrcerr );
1199 /* IB header is placed immediately before RcvHdrFlags */
1200 iob_populate ( &headers, ( ( ( void * ) rcvhdrflags ) - header_len ),
1201 header_len, header_len );
1202
1203 /* Dump diagnostic information */
1204 if ( err || ( ! useegrbfr ) ) {
1205 DBGC ( linda, "Linda %p QPN %ld RX egr %d%s hdr %d type %d "
1206 "len %d(%d+%d+4)%s%s%s%s%s%s%s%s%s%s%s\n", linda,
1207 qp->qpn, egrindex, ( useegrbfr ? "" : "(unused)" ),
1208 ( header_offs / LINDA_RECV_HEADER_SIZE ), rcvtype,
1209 pktlen, header_len, padded_payload_len,
1210 ( err ? " [Err" : "" ), ( iberr ? " IB" : "" ),
1211 ( mkerr ? " MK" : "" ), ( tiderr ? " TID" : "" ),
1212 ( khdrerr ? " KHdr" : "" ), ( mtuerr ? " MTU" : "" ),
1213 ( lenerr ? " Len" : "" ), ( parityerr ? " Parity" : ""),
1214 ( vcrcerr ? " VCRC" : "" ), ( icrcerr ? " ICRC" : "" ),
1215 ( err ? "]" : "" ) );
1216 } else {
1217 DBGC2 ( linda, "Linda %p QPN %ld RX egr %d hdr %d type %d "
1218 "len %d(%d+%d+4)\n", linda, qp->qpn, egrindex,
1219 ( header_offs / LINDA_RECV_HEADER_SIZE ), rcvtype,
1220 pktlen, header_len, padded_payload_len );
1221 }
1222 DBGCP_HDA ( linda, hdrqoffset, headers.data,
1223 ( header_len + sizeof ( *rcvhdrflags ) ) );
1224
1225 /* Parse header to generate address vector */
1226 qp0 = ( qp->qpn == 0 );
1227 intended_qp = NULL;
1228 if ( ( rc = ib_pull ( ibdev, &headers, ( qp0 ? &intended_qp : NULL ),
1229 &payload_len, &dest, &source ) ) != 0 ) {
1230 DBGC ( linda, "Linda %p could not parse headers: %s\n",
1231 linda, strerror ( rc ) );
1232 err = 1;
1233 }
1234 if ( ! intended_qp )
1235 intended_qp = qp;
1236
1237 /* Complete this buffer and any skipped buffers. Note that
1238 * when the hardware runs out of buffers, it will repeatedly
1239 * report the same buffer (the tail) as a TID error, and that
1240 * it also has a habit of sometimes skipping over several
1241 * buffers at once.
1242 */
1243 while ( 1 ) {
1244
1245 /* If we have caught up to the producer counter, stop.
1246 * This will happen when the hardware first runs out
1247 * of buffers and starts reporting TID errors against
1248 * the eager buffer it wants to use next.
1249 */
1250 if ( linda_wq->eager_cons == linda_wq->eager_prod )
1251 break;
1252
1253 /* If we have caught up to where we should be after
1254 * completing this egrindex, stop. We phrase the test
1255 * this way to avoid completing the entire ring when
1256 * we receive the same egrindex twice in a row.
1257 */
1258 if ( ( linda_wq->eager_cons ==
1259 ( ( egrindex + 1 ) & ( linda_wq->eager_entries - 1 ) )))
1260 break;
1261
1262 /* Identify work queue entry and corresponding I/O
1263 * buffer.
1264 */
1265 wqe_idx = ( linda_wq->eager_cons & ( wq->num_wqes - 1 ) );
1266 iobuf = wq->iobufs[wqe_idx];
1267 assert ( iobuf != NULL );
1268 wq->iobufs[wqe_idx] = NULL;
1269
1270 /* Complete the eager buffer */
1271 if ( linda_wq->eager_cons == egrindex ) {
1272 /* Completing the eager buffer described in
1273 * this header entry.
1274 */
1275 if ( payload_len <= iob_tailroom ( iobuf ) ) {
1276 iob_put ( iobuf, payload_len );
1277 rc = ( err ?
1278 -EIO : ( useegrbfr ? 0 : -ECANCELED ) );
1279 } else {
1280 DBGC ( linda, "Linda %p bad payload len %zd\n",
1281 linda, payload_len );
1282 rc = -EPROTO;
1283 }
1284 /* Redirect to target QP if necessary */
1285 if ( qp != intended_qp ) {
1286 DBGC ( linda, "Linda %p redirecting QPN %ld "
1287 "=> %ld\n",
1288 linda, qp->qpn, intended_qp->qpn );
1289 /* Compensate for incorrect fill levels */
1290 qp->recv.fill--;
1291 intended_qp->recv.fill++;
1292 }
1293 ib_complete_recv ( ibdev, intended_qp, &dest, &source,
1294 iobuf, rc );
1295 } else {
1296 /* Completing on a skipped-over eager buffer */
1297 ib_complete_recv ( ibdev, qp, &dest, &source, iobuf,
1298 -ECANCELED );
1299 }
1300
1301 /* Clear eager buffer */
1302 memset ( &rcvegr, 0, sizeof ( rcvegr ) );
1303 linda_writeq_array8b ( linda, &rcvegr, linda_wq->eager_array,
1304 linda_wq->eager_cons );
1305
1306 /* Increment consumer index */
1307 linda_wq->eager_cons = ( ( linda_wq->eager_cons + 1 ) &
1308 ( linda_wq->eager_entries - 1 ) );
1309 }
1310}
1311
1312/**
1313 * Poll receive work queue
1314 *
1315 * @v ibdev Infiniband device
1316 * @v qp Queue pair
1317 */
1318static void linda_poll_recv_wq ( struct ib_device *ibdev,
1319 struct ib_queue_pair *qp ) {
1320 struct linda *linda = ib_get_drvdata ( ibdev );
1321 struct ib_work_queue *wq = &qp->recv;
1322 struct linda_recv_work_queue *linda_wq = ib_wq_get_drvdata ( wq );
1323 struct QIB_7220_RcvHdrHead0 rcvhdrhead;
1324 unsigned int ctx = linda_qpn_to_ctx ( qp->qpn );
1325 unsigned int header_prod;
1326
1327 /* Check for received packets */
1328 header_prod = ( BIT_GET ( &linda_wq->header_prod, Value ) << 2 );
1329 if ( header_prod == linda_wq->header_cons )
1330 return;
1331
1332 /* Process all received packets */
1333 while ( linda_wq->header_cons != header_prod ) {
1334
1335 /* Complete the receive */
1336 linda_complete_recv ( ibdev, qp, linda_wq->header_cons );
1337
1338 /* Increment the consumer offset */
1341 }
1342
1343 /* Update consumer offset */
1344 memset ( &rcvhdrhead, 0, sizeof ( rcvhdrhead ) );
1345 BIT_FILL_2 ( &rcvhdrhead,
1346 RcvHeadPointer, ( linda_wq->header_cons >> 2 ),
1347 counter, 1 );
1348 linda_writeq_array64k ( linda, &rcvhdrhead,
1350}
1351
1352/**
1353 * Poll completion queue
1354 *
1355 * @v ibdev Infiniband device
1356 * @v cq Completion queue
1357 */
1358static void linda_poll_cq ( struct ib_device *ibdev,
1359 struct ib_completion_queue *cq ) {
1360 struct ib_work_queue *wq;
1361
1362 /* Poll associated send and receive queues */
1364 if ( wq->is_send ) {
1365 linda_poll_send_wq ( ibdev, wq->qp );
1366 } else {
1367 linda_poll_recv_wq ( ibdev, wq->qp );
1368 }
1369 }
1370}
1371
1372/***************************************************************************
1373 *
1374 * Event queues
1375 *
1376 ***************************************************************************
1377 */
1378
1379/**
1380 * Poll event queue
1381 *
1382 * @v ibdev Infiniband device
1383 */
1384static void linda_poll_eq ( struct ib_device *ibdev ) {
1385 struct linda *linda = ib_get_drvdata ( ibdev );
1386 struct QIB_7220_ErrStatus errstatus;
1387 struct QIB_7220_ErrClear errclear;
1388
1389 /* Check for link status changes */
1393 if ( BIT_GET ( &errstatus, IBStatusChanged ) ) {
1394 linda_link_state_changed ( ibdev );
1395 memset ( &errclear, 0, sizeof ( errclear ) );
1396 BIT_FILL_1 ( &errclear, IBStatusChangedClear, 1 );
1398 }
1399}
1400
1401/***************************************************************************
1402 *
1403 * Infiniband link-layer operations
1404 *
1405 ***************************************************************************
1406 */
1407
1408/**
1409 * Initialise Infiniband link
1410 *
1411 * @v ibdev Infiniband device
1412 * @ret rc Return status code
1413 */
1414static int linda_open ( struct ib_device *ibdev ) {
1415 struct linda *linda = ib_get_drvdata ( ibdev );
1417
1418 /* Disable link */
1420 BIT_SET ( &control, LinkEn, 1 );
1422 return 0;
1423}
1424
1425/**
1426 * Close Infiniband link
1427 *
1428 * @v ibdev Infiniband device
1429 */
1430static void linda_close ( struct ib_device *ibdev ) {
1431 struct linda *linda = ib_get_drvdata ( ibdev );
1433
1434 /* Disable link */
1436 BIT_SET ( &control, LinkEn, 0 );
1438}
1439
1440/***************************************************************************
1441 *
1442 * Multicast group operations
1443 *
1444 ***************************************************************************
1445 */
1446
1447/**
1448 * Attach to multicast group
1449 *
1450 * @v ibdev Infiniband device
1451 * @v qp Queue pair
1452 * @v gid Multicast GID
1453 * @ret rc Return status code
1454 */
1455static int linda_mcast_attach ( struct ib_device *ibdev,
1456 struct ib_queue_pair *qp,
1457 union ib_gid *gid ) {
1458 struct linda *linda = ib_get_drvdata ( ibdev );
1459
1460 ( void ) linda;
1461 ( void ) qp;
1462 ( void ) gid;
1463 return 0;
1464}
1465
1466/**
1467 * Detach from multicast group
1468 *
1469 * @v ibdev Infiniband device
1470 * @v qp Queue pair
1471 * @v gid Multicast GID
1472 */
1473static void linda_mcast_detach ( struct ib_device *ibdev,
1474 struct ib_queue_pair *qp,
1475 union ib_gid *gid ) {
1476 struct linda *linda = ib_get_drvdata ( ibdev );
1477
1478 ( void ) linda;
1479 ( void ) qp;
1480 ( void ) gid;
1481}
1482
1483/** Linda Infiniband operations */
1485 .create_cq = linda_create_cq,
1486 .destroy_cq = linda_destroy_cq,
1487 .create_qp = linda_create_qp,
1488 .modify_qp = linda_modify_qp,
1489 .destroy_qp = linda_destroy_qp,
1490 .post_send = linda_post_send,
1491 .post_recv = linda_post_recv,
1492 .poll_cq = linda_poll_cq,
1493 .poll_eq = linda_poll_eq,
1494 .open = linda_open,
1495 .close = linda_close,
1496 .mcast_attach = linda_mcast_attach,
1497 .mcast_detach = linda_mcast_detach,
1498 .set_port_info = linda_set_port_info,
1499 .set_pkey_table = linda_set_pkey_table,
1500};
1501
1502/***************************************************************************
1503 *
1504 * I2C bus operations
1505 *
1506 ***************************************************************************
1507 */
1508
1509/** Linda I2C bit to GPIO mappings */
1510static unsigned int linda_i2c_bits[] = {
1511 [I2C_BIT_SCL] = ( 1 << LINDA_GPIO_SCL ),
1512 [I2C_BIT_SDA] = ( 1 << LINDA_GPIO_SDA ),
1513};
1514
1515/**
1516 * Read Linda I2C line status
1517 *
1518 * @v basher Bit-bashing interface
1519 * @v bit_id Bit number
1520 * @ret zero Input is a logic 0
1521 * @ret non-zero Input is a logic 1
1522 */
1523static int linda_i2c_read_bit ( struct bit_basher *basher,
1524 unsigned int bit_id ) {
1525 struct linda *linda =
1526 container_of ( basher, struct linda, i2c.basher );
1527 struct QIB_7220_EXTStatus extstatus;
1528 unsigned int status;
1529
1531
1533 status = ( BIT_GET ( &extstatus, GPIOIn ) & linda_i2c_bits[bit_id] );
1534
1536
1537 return status;
1538}
1539
1540/**
1541 * Write Linda I2C line status
1542 *
1543 * @v basher Bit-bashing interface
1544 * @v bit_id Bit number
1545 * @v data Value to write
1546 */
1547static void linda_i2c_write_bit ( struct bit_basher *basher,
1548 unsigned int bit_id, unsigned long data ) {
1549 struct linda *linda =
1550 container_of ( basher, struct linda, i2c.basher );
1551 struct QIB_7220_EXTCtrl extctrl;
1552 struct QIB_7220_GPIO gpioout;
1553 unsigned int bit = linda_i2c_bits[bit_id];
1554 unsigned int outputs = 0;
1555 unsigned int output_enables = 0;
1556
1558
1559 /* Read current GPIO mask and outputs */
1562
1563 /* Update outputs and output enables. I2C lines are tied
1564 * high, so we always set the output to 0 and use the output
1565 * enable to control the line.
1566 */
1567 output_enables = BIT_GET ( &extctrl, GPIOOe );
1568 output_enables = ( ( output_enables & ~bit ) | ( ~data & bit ) );
1569 outputs = BIT_GET ( &gpioout, GPIO );
1570 outputs = ( outputs & ~bit );
1571 BIT_SET ( &extctrl, GPIOOe, output_enables );
1572 BIT_SET ( &gpioout, GPIO, outputs );
1573
1574 /* Write the output enable first; that way we avoid logic
1575 * hazards.
1576 */
1579 mb();
1580
1582}
1583
1584/** Linda I2C bit-bashing interface operations */
1586 .read = linda_i2c_read_bit,
1587 .write = linda_i2c_write_bit,
1588};
1589
1590/**
1591 * Initialise Linda I2C subsystem
1592 *
1593 * @v linda Linda device
1594 * @ret rc Return status code
1595 */
1596static int linda_init_i2c ( struct linda *linda ) {
1597 static int try_eeprom_address[] = { 0x51, 0x50 };
1598 unsigned int i;
1599 int rc;
1600
1601 /* Initialise bus */
1602 if ( ( rc = init_i2c_bit_basher ( &linda->i2c,
1603 &linda_i2c_basher_ops ) ) != 0 ) {
1604 DBGC ( linda, "Linda %p could not initialise I2C bus: %s\n",
1605 linda, strerror ( rc ) );
1606 return rc;
1607 }
1608
1609 /* Probe for devices */
1610 for ( i = 0 ; i < ( sizeof ( try_eeprom_address ) /
1611 sizeof ( try_eeprom_address[0] ) ) ; i++ ) {
1612 init_i2c_eeprom ( &linda->eeprom, try_eeprom_address[i] );
1613 if ( ( rc = i2c_check_presence ( &linda->i2c.i2c,
1614 &linda->eeprom ) ) == 0 ) {
1615 DBGC2 ( linda, "Linda %p found EEPROM at %02x\n",
1616 linda, try_eeprom_address[i] );
1617 return 0;
1618 }
1619 }
1620
1621 DBGC ( linda, "Linda %p could not find EEPROM\n", linda );
1622 return -ENODEV;
1623}
1624
1625/**
1626 * Read EEPROM parameters
1627 *
1628 * @v linda Linda device
1629 * @v guid GUID to fill in
1630 * @ret rc Return status code
1631 */
1632static int linda_read_eeprom ( struct linda *linda, union ib_guid *guid ) {
1633 struct i2c_interface *i2c = &linda->i2c.i2c;
1634 int rc;
1635
1636 /* Read GUID */
1637 if ( ( rc = i2c->read ( i2c, &linda->eeprom, LINDA_EEPROM_GUID_OFFSET,
1638 guid->bytes, sizeof ( *guid ) ) ) != 0 ) {
1639 DBGC ( linda, "Linda %p could not read GUID: %s\n",
1640 linda, strerror ( rc ) );
1641 return rc;
1642 }
1643 DBGC2 ( linda, "Linda %p has GUID " IB_GUID_FMT "\n",
1644 linda, IB_GUID_ARGS ( guid ) );
1645
1646 /* Read serial number (debug only) */
1647 if ( DBG_LOG ) {
1649
1650 serial[ sizeof ( serial ) - 1 ] = '\0';
1651 if ( ( rc = i2c->read ( i2c, &linda->eeprom,
1653 ( sizeof ( serial ) - 1 ) ) ) != 0 ) {
1654 DBGC ( linda, "Linda %p could not read serial: %s\n",
1655 linda, strerror ( rc ) );
1656 return rc;
1657 }
1658 DBGC2 ( linda, "Linda %p has serial number \"%s\"\n",
1659 linda, serial );
1660 }
1661
1662 return 0;
1663}
1664
1665/***************************************************************************
1666 *
1667 * External parallel bus access
1668 *
1669 ***************************************************************************
1670 */
1671
1672/**
1673 * Request ownership of the IB external parallel bus
1674 *
1675 * @v linda Linda device
1676 * @ret rc Return status code
1677 */
1678static int linda_ib_epb_request ( struct linda *linda ) {
1679 struct QIB_7220_ibsd_epb_access_ctrl access;
1680 unsigned int i;
1681
1682 /* Request ownership */
1683 memset ( &access, 0, sizeof ( access ) );
1684 BIT_FILL_1 ( &access, sw_ib_epb_req, 1 );
1686
1687 /* Wait for ownership to be granted */
1688 for ( i = 0 ; i < LINDA_EPB_REQUEST_MAX_WAIT_US ; i++ ) {
1689 linda_readq ( linda, &access,
1691 if ( BIT_GET ( &access, sw_ib_epb_req_granted ) )
1692 return 0;
1693 udelay ( 1 );
1694 }
1695
1696 DBGC ( linda, "Linda %p timed out waiting for IB EPB request\n",
1697 linda );
1698 return -ETIMEDOUT;
1699}
1700
1701/**
1702 * Wait for IB external parallel bus transaction to complete
1703 *
1704 * @v linda Linda device
1705 * @v xact Buffer to hold transaction result
1706 * @ret rc Return status code
1707 */
1708static int linda_ib_epb_wait ( struct linda *linda,
1710 unsigned int i;
1711
1712 /* Discard first read to allow for signals crossing clock domains */
1714
1715 for ( i = 0 ; i < LINDA_EPB_XACT_MAX_WAIT_US ; i++ ) {
1718 if ( BIT_GET ( xact, ib_epb_rdy ) ) {
1719 if ( BIT_GET ( xact, ib_epb_req_error ) ) {
1720 DBGC ( linda, "Linda %p EPB transaction "
1721 "failed\n", linda );
1722 return -EIO;
1723 } else {
1724 return 0;
1725 }
1726 }
1727 udelay ( 1 );
1728 }
1729
1730 DBGC ( linda, "Linda %p timed out waiting for IB EPB transaction\n",
1731 linda );
1732 return -ETIMEDOUT;
1733}
1734
1735/**
1736 * Release ownership of the IB external parallel bus
1737 *
1738 * @v linda Linda device
1739 */
1740static void linda_ib_epb_release ( struct linda *linda ) {
1741 struct QIB_7220_ibsd_epb_access_ctrl access;
1742
1743 memset ( &access, 0, sizeof ( access ) );
1744 BIT_FILL_1 ( &access, sw_ib_epb_req, 0 );
1746}
1747
1748/**
1749 * Read data via IB external parallel bus
1750 *
1751 * @v linda Linda device
1752 * @v location EPB location
1753 * @ret data Data read, or negative error
1754 *
1755 * You must have already acquired ownership of the IB external
1756 * parallel bus.
1757 */
1758static int linda_ib_epb_read ( struct linda *linda, unsigned int location ) {
1760 unsigned int data;
1761 int rc;
1762
1763 /* Ensure no transaction is currently in progress */
1764 if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
1765 return rc;
1766
1767 /* Process data */
1768 memset ( &xact, 0, sizeof ( xact ) );
1769 BIT_FILL_3 ( &xact,
1770 ib_epb_address, LINDA_EPB_LOC_ADDRESS ( location ),
1771 ib_epb_read_write, LINDA_EPB_READ,
1772 ib_epb_cs, LINDA_EPB_LOC_CS ( location ) );
1775
1776 /* Wait for transaction to complete */
1777 if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
1778 return rc;
1779
1780 data = BIT_GET ( &xact, ib_epb_data );
1781 return data;
1782}
1783
1784/**
1785 * Write data via IB external parallel bus
1786 *
1787 * @v linda Linda device
1788 * @v location EPB location
1789 * @v data Data to write
1790 * @ret rc Return status code
1791 *
1792 * You must have already acquired ownership of the IB external
1793 * parallel bus.
1794 */
1795static int linda_ib_epb_write ( struct linda *linda, unsigned int location,
1796 unsigned int data ) {
1798 int rc;
1799
1800 /* Ensure no transaction is currently in progress */
1801 if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
1802 return rc;
1803
1804 /* Process data */
1805 memset ( &xact, 0, sizeof ( xact ) );
1806 BIT_FILL_4 ( &xact,
1807 ib_epb_data, data,
1808 ib_epb_address, LINDA_EPB_LOC_ADDRESS ( location ),
1809 ib_epb_read_write, LINDA_EPB_WRITE,
1810 ib_epb_cs, LINDA_EPB_LOC_CS ( location ) );
1813
1814 /* Wait for transaction to complete */
1815 if ( ( rc = linda_ib_epb_wait ( linda, &xact ) ) != 0 )
1816 return rc;
1817
1818 return 0;
1819}
1820
1821/**
1822 * Read/modify/write EPB register
1823 *
1824 * @v linda Linda device
1825 * @v cs Chip select
1826 * @v channel Channel
1827 * @v element Element
1828 * @v reg Register
1829 * @v value Value to set
1830 * @v mask Mask to apply to old value
1831 * @ret rc Return status code
1832 */
1833static int linda_ib_epb_mod_reg ( struct linda *linda, unsigned int cs,
1834 unsigned int channel, unsigned int element,
1835 unsigned int reg, unsigned int value,
1836 unsigned int mask ) {
1837 unsigned int location;
1838 int old_value;
1839 int rc;
1840
1842
1843 /* Sanity check */
1844 assert ( ( value & mask ) == value );
1845
1846 /* Acquire bus ownership */
1847 if ( ( rc = linda_ib_epb_request ( linda ) ) != 0 )
1848 goto out;
1849
1850 /* Read existing value, if necessary */
1851 location = LINDA_EPB_LOC ( cs, channel, element, reg );
1852 if ( (~mask) & 0xff ) {
1853 old_value = linda_ib_epb_read ( linda, location );
1854 if ( old_value < 0 ) {
1855 rc = old_value;
1856 goto out_release;
1857 }
1858 } else {
1859 old_value = 0;
1860 }
1861
1862 /* Update value */
1863 value = ( ( old_value & ~mask ) | value );
1864 DBGCP ( linda, "Linda %p CS %d EPB(%d,%d,%#02x) %#02x => %#02x\n",
1865 linda, cs, channel, element, reg, old_value, value );
1866 if ( ( rc = linda_ib_epb_write ( linda, location, value ) ) != 0 )
1867 goto out_release;
1868
1869 out_release:
1870 /* Release bus */
1872 out:
1874 return rc;
1875}
1876
1877/**
1878 * Transfer data to/from microcontroller RAM
1879 *
1880 * @v linda Linda device
1881 * @v address Starting address
1882 * @v write Data to write, or NULL
1883 * @v read Data to read, or NULL
1884 * @v len Length of data
1885 * @ret rc Return status code
1886 */
1887static int linda_ib_epb_ram_xfer ( struct linda *linda, unsigned int address,
1888 const void *write, void *read,
1889 size_t len ) {
1890 unsigned int control;
1891 unsigned int address_hi;
1892 unsigned int address_lo;
1893 int data;
1894 int rc;
1895
1897
1898 assert ( ! ( write && read ) );
1899 assert ( ( address % LINDA_EPB_UC_CHUNK_SIZE ) == 0 );
1900 assert ( ( len % LINDA_EPB_UC_CHUNK_SIZE ) == 0 );
1901
1902 /* Acquire bus ownership */
1903 if ( ( rc = linda_ib_epb_request ( linda ) ) != 0 )
1904 goto out;
1905
1906 /* Process data */
1907 while ( len ) {
1908
1909 /* Reset the address for each new chunk */
1910 if ( ( address % LINDA_EPB_UC_CHUNK_SIZE ) == 0 ) {
1911
1912 /* Write the control register */
1915 if ( ( rc = linda_ib_epb_write ( linda,
1917 control ) ) != 0 )
1918 break;
1919
1920 /* Write the address registers */
1921 address_hi = ( address >> 8 );
1922 if ( ( rc = linda_ib_epb_write ( linda,
1924 address_hi ) ) != 0 )
1925 break;
1926 address_lo = ( address & 0xff );
1927 if ( ( rc = linda_ib_epb_write ( linda,
1929 address_lo ) ) != 0 )
1930 break;
1931 }
1932
1933 /* Read or write the data */
1934 if ( read ) {
1936 if ( data < 0 ) {
1937 rc = data;
1938 break;
1939 }
1940 *( ( uint8_t * ) read++ ) = data;
1941 } else {
1942 data = *( ( uint8_t * ) write++ );
1943 if ( ( rc = linda_ib_epb_write ( linda,
1945 data ) ) != 0 )
1946 break;
1947 }
1948 address++;
1949 len--;
1950
1951 /* Reset the control byte after each chunk */
1952 if ( ( address % LINDA_EPB_UC_CHUNK_SIZE ) == 0 ) {
1953 if ( ( rc = linda_ib_epb_write ( linda,
1955 0 ) ) != 0 )
1956 break;
1957 }
1958 }
1959
1960 /* Release bus */
1962
1963 out:
1965 return rc;
1966}
1967
1968/***************************************************************************
1969 *
1970 * Infiniband SerDes initialisation
1971 *
1972 ***************************************************************************
1973 */
1974
1975/** A Linda SerDes parameter */
1977 /** EPB address as constructed by LINDA_EPB_ADDRESS() */
1979 /** Value to set */
1981 /** Mask to apply to old value */
1984
1985/** Magic "all channels" channel number */
1986#define LINDA_EPB_ALL_CHANNELS 31
1987
1988/** End of SerDes parameter list marker */
1989#define LINDA_SERDES_PARAM_END { 0, 0, 0 }
1990
1991/**
1992 * Program IB SerDes register(s)
1993 *
1994 * @v linda Linda device
1995 * @v param SerDes parameter
1996 * @ret rc Return status code
1997 */
1999 struct linda_serdes_param *param ) {
2000 unsigned int channel;
2001 unsigned int channel_start;
2002 unsigned int channel_end;
2003 unsigned int element;
2004 unsigned int reg;
2005 int rc;
2006
2007 /* Break down the EPB address and determine channels */
2010 reg = LINDA_EPB_ADDRESS_REG ( param->address );
2012 channel_start = 0;
2013 channel_end = 3;
2014 } else {
2015 channel_start = channel_end = channel;
2016 }
2017
2018 /* Modify register for each specified channel */
2019 for ( channel = channel_start ; channel <= channel_end ; channel++ ) {
2022 param->value,
2023 param->mask ) ) != 0 )
2024 return rc;
2025 }
2026
2027 return 0;
2028}
2029
2030/**
2031 * Program IB SerDes registers
2032 *
2033 * @v linda Linda device
2034 * @v param SerDes parameters
2035 * @v count Number of parameters
2036 * @ret rc Return status code
2037 */
2039 struct linda_serdes_param *params ) {
2040 int rc;
2041
2042 for ( ; params->mask != 0 ; params++ ){
2043 if ( ( rc = linda_set_serdes_param ( linda,
2044 params ) ) != 0 )
2045 return rc;
2046 }
2047
2048 return 0;
2049}
2050
2051#define LINDA_DDS_VAL( amp_d, main_d, ipst_d, ipre_d, \
2052 amp_s, main_s, ipst_s, ipre_s ) \
2053 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x00 ), \
2054 ( ( ( amp_d & 0x1f ) << 1 ) | 1 ), 0xff }, \
2055 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x01 ), \
2056 ( ( ( amp_s & 0x1f ) << 1 ) | 1 ), 0xff }, \
2057 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x09 ), \
2058 ( ( main_d << 3 ) | 4 | ( ipre_d >> 2 ) ), 0xff }, \
2059 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x0a ), \
2060 ( ( main_s << 3 ) | 4 | ( ipre_s >> 2 ) ), 0xff }, \
2061 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x06 ), \
2062 ( ( ( ipst_d & 0xf ) << 1 ) | \
2063 ( ( ipre_d & 3 ) << 6 ) | 0x21 ), 0xff }, \
2064 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 9, 0x07 ), \
2065 ( ( ( ipst_s & 0xf ) << 1 ) | \
2066 ( ( ipre_s & 3 ) << 6) | 0x21 ), 0xff }
2067
2068/**
2069 * Linda SerDes default parameters
2070 *
2071 * These magic start-of-day values are taken from the Linux driver.
2072 */
2074 /* RXHSCTRL0 */
2075 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x00 ), 0xd4, 0xff },
2076 /* VCDL_DAC2 */
2077 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x05 ), 0x2d, 0xff },
2078 /* VCDL_CTRL2 */
2079 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x08 ), 0x03, 0x0f },
2080 /* START_EQ1 */
2081 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x27 ), 0x10, 0xff },
2082 /* START_EQ2 */
2083 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x28 ), 0x30, 0xff },
2084 /* BACTRL */
2085 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x0e ), 0x40, 0xff },
2086 /* LDOUTCTRL1 */
2087 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x06 ), 0x04, 0xff },
2088 /* RXHSSTATUS */
2089 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x0f ), 0x04, 0xff },
2090 /* End of this block */
2092};
2094 /* LDOUTCTRL1 */
2095 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x06 ), 0x00, 0xff },
2096 /* DDS values */
2097 LINDA_DDS_VAL ( 31, 19, 12, 0, 29, 22, 9, 0 ),
2098 /* Set Rcv Eq. to Preset node */
2099 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x27 ), 0x10, 0xff },
2100 /* DFELTHFDR */
2101 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x08 ), 0x00, 0xff },
2102 /* DFELTHHDR */
2103 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x21 ), 0x00, 0xff },
2104 /* TLTHFDR */
2105 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x09 ), 0x02, 0xff },
2106 /* TLTHHDR */
2107 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x23 ), 0x02, 0xff },
2108 /* ZFR */
2109 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1b ), 0x0c, 0xff },
2110 /* ZCNT) */
2111 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1c ), 0x0c, 0xff },
2112 /* GFR */
2113 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1e ), 0x10, 0xff },
2114 /* GHR */
2115 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x1f ), 0x10, 0xff },
2116 /* VCDL_CTRL0 toggle */
2117 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x06 ), 0x20, 0xff },
2118 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 6, 0x06 ), 0x00, 0xff },
2119 /* CMUCTRL5 */
2120 { LINDA_EPB_ADDRESS ( 7, 0, 0x15 ), 0x80, 0xff },
2121 /* End of this block */
2123};
2125 /* START_EQ1 */
2126 { LINDA_EPB_ADDRESS ( LINDA_EPB_ALL_CHANNELS, 7, 0x27 ), 0x00, 0x38 },
2127 /* End of this block */
2129};
2130
2131/**
2132 * Program the microcontroller RAM
2133 *
2134 * @v linda Linda device
2135 * @ret rc Return status code
2136 */
2137static int linda_program_uc_ram ( struct linda *linda ) {
2138 int rc;
2139
2141 sizeof ( linda_ib_fw ) ) ) != 0 ){
2142 DBGC ( linda, "Linda %p could not load IB firmware: %s\n",
2143 linda, strerror ( rc ) );
2144 return rc;
2145 }
2146
2147 return 0;
2148}
2149
2150/**
2151 * Verify the microcontroller RAM
2152 *
2153 * @v linda Linda device
2154 * @ret rc Return status code
2155 */
2156static int linda_verify_uc_ram ( struct linda *linda ) {
2158 unsigned int offset;
2159 int rc;
2160
2161 for ( offset = 0 ; offset < sizeof ( linda_ib_fw );
2162 offset += sizeof ( verify ) ) {
2164 NULL, verify,
2165 sizeof (verify) )) != 0 ){
2166 DBGC ( linda, "Linda %p could not read back IB "
2167 "firmware: %s\n", linda, strerror ( rc ) );
2168 return rc;
2169 }
2170 if ( memcmp ( ( linda_ib_fw + offset ), verify,
2171 sizeof ( verify ) ) != 0 ) {
2172 DBGC ( linda, "Linda %p firmware verification failed "
2173 "at offset %#x\n", linda, offset );
2175 sizeof ( verify ) );
2176 DBGC_HDA ( linda, offset, verify, sizeof ( verify ) );
2177 return -EIO;
2178 }
2179 }
2180
2181 DBGC2 ( linda, "Linda %p firmware verified ok\n", linda );
2182 return 0;
2183}
2184
2185/**
2186 * Use the microcontroller to trim the IB link
2187 *
2188 * @v linda Linda device
2189 * @ret rc Return status code
2190 */
2191static int linda_trim_ib ( struct linda *linda ) {
2193 struct QIB_7220_IntStatus intstatus;
2194 unsigned int i;
2195 int rc;
2196
2197 /* Bring the microcontroller out of reset */
2199 BIT_SET ( &ctrl, ResetIB_uC_Core, 0 );
2201
2202 /* Wait for the "trim done" signal */
2203 for ( i = 0 ; i < LINDA_TRIM_DONE_MAX_WAIT_MS ; i++ ) {
2205 if ( BIT_GET ( &intstatus, IBSerdesTrimDone ) ) {
2206 rc = 0;
2207 goto out_reset;
2208 }
2209 mdelay ( 1 );
2210 }
2211
2212 DBGC ( linda, "Linda %p timed out waiting for trim done\n", linda );
2213 rc = -ETIMEDOUT;
2214 out_reset:
2215 /* Put the microcontroller back into reset */
2216 BIT_SET ( &ctrl, ResetIB_uC_Core, 1 );
2218
2219 return rc;
2220}
2221
2222/**
2223 * Initialise the IB SerDes
2224 *
2225 * @v linda Linda device
2226 * @ret rc Return status code
2227 */
2228static int linda_init_ib_serdes ( struct linda *linda ) {
2230 struct QIB_7220_IBCCtrl ibcctrl;
2231 struct QIB_7220_IBCDDRCtrl ibcddrctrl;
2232 struct QIB_7220_XGXSCfg xgxscfg;
2233 int rc;
2234
2235 /* Disable link */
2237 BIT_SET ( &control, LinkEn, 0 );
2239
2240 /* Configure sensible defaults for IBC */
2241 memset ( &ibcctrl, 0, sizeof ( ibcctrl ) );
2242 BIT_FILL_6 ( &ibcctrl, /* Tuning values taken from Linux driver */
2243 FlowCtrlPeriod, 0x03,
2244 FlowCtrlWaterMark, 0x05,
2245 MaxPktLen, ( ( LINDA_RECV_HEADER_SIZE +
2247 4 /* ICRC */ ) >> 2 ),
2248 PhyerrThreshold, 0xf,
2249 OverrunThreshold, 0xf,
2250 CreditScale, 0x4 );
2252
2253 /* Force SDR only to avoid needing all the DDR tuning,
2254 * Mellanox compatibility hacks etc. SDR is plenty for
2255 * boot-time operation.
2256 */
2258 BIT_SET ( &ibcddrctrl, IB_ENHANCED_MODE, 0 );
2259 BIT_SET ( &ibcddrctrl, SD_SPEED_SDR, 1 );
2260 BIT_SET ( &ibcddrctrl, SD_SPEED_DDR, 0 );
2261 BIT_SET ( &ibcddrctrl, SD_SPEED_QDR, 0 );
2262 BIT_SET ( &ibcddrctrl, HRTBT_ENB, 0 );
2263 BIT_SET ( &ibcddrctrl, HRTBT_AUTO, 0 );
2265
2266 /* Set default SerDes parameters */
2267 if ( ( rc = linda_set_serdes_params ( linda,
2268 linda_serdes_defaults1 ) ) != 0 )
2269 return rc;
2270 udelay ( 415 ); /* Magic delay while SerDes sorts itself out */
2271 if ( ( rc = linda_set_serdes_params ( linda,
2272 linda_serdes_defaults2 ) ) != 0 )
2273 return rc;
2274
2275 /* Program the microcontroller RAM */
2276 if ( ( rc = linda_program_uc_ram ( linda ) ) != 0 )
2277 return rc;
2278
2279 /* Verify the microcontroller RAM contents */
2280 if ( DBGLVL_LOG ) {
2281 if ( ( rc = linda_verify_uc_ram ( linda ) ) != 0 )
2282 return rc;
2283 }
2284
2285 /* More SerDes tuning */
2286 if ( ( rc = linda_set_serdes_params ( linda,
2287 linda_serdes_defaults3 ) ) != 0 )
2288 return rc;
2289
2290 /* Use the microcontroller to trim the IB link */
2291 if ( ( rc = linda_trim_ib ( linda ) ) != 0 )
2292 return rc;
2293
2294 /* Bring XGXS out of reset */
2296 BIT_SET ( &xgxscfg, tx_rx_reset, 0 );
2297 BIT_SET ( &xgxscfg, xcv_reset, 0 );
2299
2300 return rc;
2301}
2302
2303/***************************************************************************
2304 *
2305 * PCI layer interface
2306 *
2307 ***************************************************************************
2308 */
2309
2310/**
2311 * Probe PCI device
2312 *
2313 * @v pci PCI device
2314 * @v id PCI ID
2315 * @ret rc Return status code
2316 */
2317static int linda_probe ( struct pci_device *pci ) {
2318 struct ib_device *ibdev;
2319 struct linda *linda;
2321 int rc;
2322
2323 /* Allocate Infiniband device */
2324 ibdev = alloc_ibdev ( sizeof ( *linda ) );
2325 if ( ! ibdev ) {
2326 rc = -ENOMEM;
2327 goto err_alloc_ibdev;
2328 }
2329 pci_set_drvdata ( pci, ibdev );
2330 linda = ib_get_drvdata ( ibdev );
2331 ibdev->op = &linda_ib_operations;
2332 ibdev->dev = &pci->dev;
2333 ibdev->port = 1;
2334 ibdev->ports = 1;
2335
2336 /* Fix up PCI device */
2337 adjust_pci_device ( pci );
2338
2339 /* Map PCI BARs */
2340 linda->regs = pci_ioremap ( pci, pci->membase, LINDA_BAR0_SIZE );
2341 DBGC2 ( linda, "Linda %p has BAR at %08lx\n", linda, pci->membase );
2342
2343 /* Print some general data */
2345 DBGC2 ( linda, "Linda %p board %02lx v%ld.%ld.%ld.%ld\n", linda,
2346 BIT_GET ( &revision, BoardID ),
2347 BIT_GET ( &revision, R_SW ),
2348 BIT_GET ( &revision, R_Arch ),
2349 BIT_GET ( &revision, R_ChipRevMajor ),
2350 BIT_GET ( &revision, R_ChipRevMinor ) );
2351
2352 /* Record link capabilities. Note that we force SDR only to
2353 * avoid having to carry extra code for DDR tuning etc.
2354 */
2359
2360 /* Initialise I2C subsystem */
2361 if ( ( rc = linda_init_i2c ( linda ) ) != 0 )
2362 goto err_init_i2c;
2363
2364 /* Read EEPROM parameters */
2365 if ( ( rc = linda_read_eeprom ( linda, &ibdev->node_guid ) ) != 0 )
2366 goto err_read_eeprom;
2367 memcpy ( &ibdev->gid.s.guid, &ibdev->node_guid,
2368 sizeof ( ibdev->gid.s.guid ) );
2369
2370 /* Initialise send datapath */
2371 if ( ( rc = linda_init_send ( linda ) ) != 0 )
2372 goto err_init_send;
2373
2374 /* Initialise receive datapath */
2375 if ( ( rc = linda_init_recv ( linda ) ) != 0 )
2376 goto err_init_recv;
2377
2378 /* Initialise the IB SerDes */
2379 if ( ( rc = linda_init_ib_serdes ( linda ) ) != 0 )
2380 goto err_init_ib_serdes;
2381
2382 /* Register Infiniband device */
2383 if ( ( rc = register_ibdev ( ibdev ) ) != 0 ) {
2384 DBGC ( linda, "Linda %p could not register IB "
2385 "device: %s\n", linda, strerror ( rc ) );
2386 goto err_register_ibdev;
2387 }
2388
2389 return 0;
2390
2391 unregister_ibdev ( ibdev );
2392 err_register_ibdev:
2394 err_init_recv:
2396 err_init_send:
2397 err_init_ib_serdes:
2398 err_read_eeprom:
2399 err_init_i2c:
2400 iounmap ( linda->regs );
2401 ibdev_put ( ibdev );
2402 err_alloc_ibdev:
2403 return rc;
2404}
2405
2406/**
2407 * Remove PCI device
2408 *
2409 * @v pci PCI device
2410 */
2411static void linda_remove ( struct pci_device *pci ) {
2412 struct ib_device *ibdev = pci_get_drvdata ( pci );
2413 struct linda *linda = ib_get_drvdata ( ibdev );
2414
2415 unregister_ibdev ( ibdev );
2418 iounmap ( linda->regs );
2419 ibdev_put ( ibdev );
2420}
2421
2422static struct pci_device_id linda_nics[] = {
2423 PCI_ROM ( 0x1077, 0x7220, "iba7220", "QLE7240/7280 HCA driver", 0 ),
2424};
2425
2426struct pci_driver linda_driver __pci_driver = {
2427 .ids = linda_nics,
2428 .id_count = ( sizeof ( linda_nics ) / sizeof ( linda_nics[0] ) ),
2429 .probe = linda_probe,
2431};
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
__be32 cqn
Definition CIB_PRM.h:1
u8 gid[16]
Definition CIB_PRM.h:3
struct golan_eq_context ctx
Definition CIB_PRM.h:0
__be32 qpn
Definition CIB_PRM.h:1
u8 port_state
Definition CIB_PRM.h:10
__be32 out[4]
Definition CIB_PRM.h:8
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
pseudo_bit_t value[0x00020]
Definition arbel.h:2
union ib_mad mad
Definition arbel.h:1
uint8_t headers[IB_MAX_HEADER_SIZE]
Definition arbel.h:3
struct arbelprm_qp_db_record qp
Definition arbel.h:2
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned long physaddr_t
Definition stdint.h:20
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
signed long ssize_t
Definition stdint.h:7
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
Assertions.
#define build_assert(condition)
Assert a condition at build time (after dead code elimination)
Definition assert.h:77
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
Bit-bashing interfaces.
uint16_t offset
Offset to command line.
Definition bzimage.h:3
uint8_t ctrl
Ring control.
Definition dwmac.h:7
ring len
Length.
Definition dwmac.h:226
uint32_t addr
Buffer address.
Definition dwmac.h:9
uint64_t serial
Serial number.
Definition edd.h:1
uint64_t guid
GUID.
Definition edd.h:1
#define __packed
Definition efx_common.h:26
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint8_t status
Status.
Definition ena.h:5
uint64_t address
Base address.
Definition ena.h:13
Error codes.
uint32_t xact
Requester transaction ID.
Definition eth_slow.h:7
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define DBGCP_HDA(...)
Definition compiler.h:540
#define DBGC2(...)
Definition compiler.h:522
#define DBGLVL_IO
Definition compiler.h:322
#define DBGLVL_LOG
Definition compiler.h:316
#define DBG_DISABLE(level)
Definition compiler.h:312
#define DBGCP(...)
Definition compiler.h:539
#define DBG_ENABLE(level)
Definition compiler.h:313
#define DBGC(...)
Definition compiler.h:505
#define DBG_LOG
Definition compiler.h:317
#define DBGC_HDA(...)
Definition compiler.h:506
uint8_t bufsize
Size of the packet, in bytes.
Definition int13.h:1
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define ENOENT
No such file or directory.
Definition errno.h:515
#define EINVAL
Invalid argument.
Definition errno.h:429
#define ETIMEDOUT
Connection timed out.
Definition errno.h:670
#define EPROTO
Protocol error.
Definition errno.h:625
#define ENOMEM
Not enough space.
Definition errno.h:535
#define EIO
Input/output error.
Definition errno.h:434
#define ECANCELED
Operation canceled.
Definition errno.h:344
#define ENOBUFS
No buffer space available.
Definition errno.h:499
#define ENODEV
No such device.
Definition errno.h:510
device nvs write
Definition threewire.h:62
I2C interface.
static int i2c_check_presence(struct i2c_interface *i2c, struct i2c_device *i2cdev)
Check presence of I2C device.
Definition i2c.h:135
@ I2C_BIT_SDA
Serial data.
Definition i2c.h:116
@ I2C_BIT_SCL
Serial clock.
Definition i2c.h:114
static __always_inline void init_i2c_eeprom(struct i2c_device *i2cdev, unsigned int dev_addr)
Initialise generic I2C EEPROM device.
Definition i2c.h:149
int init_i2c_bit_basher(struct i2c_bit_basher *i2cbit, struct bit_basher_operations *bash_op)
Initialise I2C bit-bashing interface.
Definition i2c_bit.c:387
#define IB_LINK_SPEED_DDR
Definition ib_mad.h:146
#define IB_LINK_SPEED_SDR
Definition ib_mad.h:145
#define IB_LINK_WIDTH_1X
Definition ib_mad.h:140
struct ib_port_info port_info
Definition ib_mad.h:3
uint32_t revision
Entry point revision.
Definition ib_mad.h:9
#define IB_LINK_WIDTH_4X
Definition ib_mad.h:141
int ib_pull(struct ib_device *ibdev, struct io_buffer *iobuf, struct ib_queue_pair **qp, size_t *payload_len, struct ib_address_vector *dest, struct ib_address_vector *source)
Remove IB headers.
Definition ib_packet.c:133
int ib_push(struct ib_device *ibdev, struct io_buffer *iobuf, struct ib_queue_pair *qp, size_t payload_len, const struct ib_address_vector *dest)
Add IB headers.
Definition ib_packet.c:52
#define IB_GUID_FMT
Infiniband Globally Unique Identifier debug message format.
Definition ib_packet.h:27
#define IB_MAX_HEADER_SIZE
Maximum size required for IB headers.
Definition ib_packet.h:157
#define IB_GUID_ARGS(guid)
Infiniband Globally Unique Identifier debug message arguments.
Definition ib_packet.h:30
value element[index]
Definition bigint.h:398
static unsigned int unsigned int bit
Definition bigint.h:392
struct hv_monitor_parameter param[4][32]
Parameters.
Definition hyperv.h:13
iPXE I/O API
void mb(void)
Memory barrier.
#define readq(io_addr)
Definition io.h:234
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition io.h:184
#define writeq(data, io_addr)
Definition io.h:273
void iounmap(volatile const void *io_addr)
Unmap I/O address.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
void ib_link_state_changed(struct ib_device *ibdev)
Notify of Infiniband link state change.
Definition infiniband.c:637
void ib_complete_recv(struct ib_device *ibdev, struct ib_queue_pair *qp, struct ib_address_vector *dest, struct ib_address_vector *source, struct io_buffer *iobuf, int rc)
Complete receive work queue entry.
Definition infiniband.c:536
int register_ibdev(struct ib_device *ibdev)
Register Infiniband device.
Definition infiniband.c:944
void unregister_ibdev(struct ib_device *ibdev)
Unregister Infiniband device.
Definition infiniband.c:985
void ib_complete_send(struct ib_device *ibdev, struct ib_queue_pair *qp, struct io_buffer *iobuf, int rc)
Complete send work queue entry.
Definition infiniband.c:515
struct ib_device * alloc_ibdev(size_t priv_size)
Allocate Infiniband device.
Definition infiniband.c:917
Infiniband protocol.
static __always_inline void * ib_get_drvdata(struct ib_device *ibdev)
Get Infiniband device driver-private data.
Definition infiniband.h:709
static __always_inline void * ib_wq_get_drvdata(struct ib_work_queue *wq)
Get Infiniband work queue driver-private data.
Definition infiniband.h:621
static __always_inline void ib_wq_set_drvdata(struct ib_work_queue *wq, void *priv)
Set Infiniband work queue driver-private data.
Definition infiniband.h:610
static __always_inline void ibdev_put(struct ib_device *ibdev)
Drop reference to Infiniband device.
Definition infiniband.h:599
I/O buffers.
static void iob_populate(struct io_buffer *iobuf, void *data, size_t len, size_t max_len)
Create a temporary I/O buffer.
Definition iobuf.h:195
#define iob_put(iobuf, len)
Definition iobuf.h:125
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
#define iob_reserve(iobuf, len)
Definition iobuf.h:72
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
Definition iobuf.h:180
uint32_t cs
Definition librm.h:14
static int linda_ib_epb_read(struct linda *linda, unsigned int location)
Read data via IB external parallel bus.
Definition linda.c:1758
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)
Read/modify/write EPB register.
Definition linda.c:1833
static unsigned int linda_i2c_bits[]
Linda I2C bit to GPIO mappings.
Definition linda.c:1510
static int linda_post_recv(struct ib_device *ibdev, struct ib_queue_pair *qp, struct io_buffer *iobuf)
Post receive work queue entry.
Definition linda.c:1069
static int linda_create_send_wq(struct linda *linda, struct ib_queue_pair *qp)
Create send work queue.
Definition linda.c:457
#define LINDA_DDS_VAL(amp_d, main_d, ipst_d, ipre_d, amp_s, main_s, ipst_s, ipre_s)
Definition linda.c:2051
static int linda_i2c_read_bit(struct bit_basher *basher, unsigned int bit_id)
Read Linda I2C line status.
Definition linda.c:1523
static void linda_poll_eq(struct ib_device *ibdev)
Poll event queue.
Definition linda.c:1384
static int linda_link_state_check(struct linda *linda, unsigned int new_link_state)
Wait for link state change to take effect.
Definition linda.c:236
static void linda_poll_cq(struct ib_device *ibdev, struct ib_completion_queue *cq)
Poll completion queue.
Definition linda.c:1358
static struct linda_serdes_param linda_serdes_defaults1[]
Linda SerDes default parameters.
Definition linda.c:2073
static void linda_mcast_detach(struct ib_device *ibdev, struct ib_queue_pair *qp, union ib_gid *gid)
Detach from multicast group.
Definition linda.c:1473
static void linda_writel(struct linda *linda, uint32_t dword, unsigned long offset)
Write Linda dword register.
Definition linda.c:161
static void linda_destroy_qp(struct ib_device *ibdev, struct ib_queue_pair *qp)
Destroy queue pair.
Definition linda.c:906
static void linda_destroy_send_wq(struct linda *linda, struct ib_queue_pair *qp)
Destroy send work queue.
Definition linda.c:501
#define linda_readq(_linda, _ptr, _offset)
Definition linda.c:129
#define LINDA_SERDES_PARAM_END
End of SerDes parameter list marker.
Definition linda.c:1989
static void linda_i2c_write_bit(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Write Linda I2C line status.
Definition linda.c:1547
static int linda_mcast_attach(struct ib_device *ibdev, struct ib_queue_pair *qp, union ib_gid *gid)
Attach to multicast group.
Definition linda.c:1455
static void linda_link_state_changed(struct ib_device *ibdev)
Handle link state change.
Definition linda.c:195
static int linda_post_send(struct ib_device *ibdev, struct ib_queue_pair *qp, struct ib_address_vector *dest, struct io_buffer *iobuf)
Post send work queue entry.
Definition linda.c:930
static int linda_init_ib_serdes(struct linda *linda)
Initialise the IB SerDes.
Definition linda.c:2228
#define linda_writeq(_linda, _ptr, _offset)
Definition linda.c:147
static int linda_read_eeprom(struct linda *linda, union ib_guid *guid)
Read EEPROM parameters.
Definition linda.c:1632
static int linda_open(struct ib_device *ibdev)
Initialise Infiniband link.
Definition linda.c:1414
static void linda_free_ctx(struct linda *linda, unsigned int ctx)
Free a context.
Definition linda.c:361
static void linda_free_send_buf(struct linda *linda, unsigned int send_buf)
Free a send buffer.
Definition linda.c:407
static unsigned int linda_alloc_send_buf(struct linda *linda)
Allocate a send buffer.
Definition linda.c:391
static struct linda_serdes_param linda_serdes_defaults2[]
Definition linda.c:2093
#define linda_writeq_array64k(_linda, _ptr, _offset, _idx)
Definition linda.c:151
static void linda_complete_recv(struct ib_device *ibdev, struct ib_queue_pair *qp, unsigned int header_offs)
Complete receive work queue entry.
Definition linda.c:1149
static struct pci_device_id linda_nics[]
Definition linda.c:2422
static void linda_destroy_cq(struct ib_device *ibdev, struct ib_completion_queue *cq)
Destroy completion queue.
Definition linda.c:821
static int linda_program_uc_ram(struct linda *linda)
Program the microcontroller RAM.
Definition linda.c:2137
static int linda_set_pkey_table(struct ib_device *ibdev __unused, union ib_mad *mad __unused)
Set partition key table.
Definition linda.c:297
static int linda_set_port_info(struct ib_device *ibdev, union ib_mad *mad)
Set port information.
Definition linda.c:261
static int linda_create_qp(struct ib_device *ibdev, struct ib_queue_pair *qp)
Create queue pair.
Definition linda.c:843
static void linda_close(struct ib_device *ibdev)
Close Infiniband link.
Definition linda.c:1430
static void linda_fini_recv(struct linda *linda __unused)
Shut down receive datapath.
Definition linda.c:777
static int linda_send_buf_in_use(struct linda *linda, unsigned int send_buf)
Check to see if send buffer is in use.
Definition linda.c:421
static void linda_poll_send_wq(struct ib_device *ibdev, struct ib_queue_pair *qp)
Poll send work queue.
Definition linda.c:1037
static int linda_ib_epb_write(struct linda *linda, unsigned int location, unsigned int data)
Write data via IB external parallel bus.
Definition linda.c:1795
static void linda_complete_send(struct ib_device *ibdev, struct ib_queue_pair *qp, unsigned int wqe_idx)
Complete send work queue entry.
Definition linda.c:1007
static int linda_init_send(struct linda *linda)
Initialise send datapath.
Definition linda.c:516
static struct ib_device_operations linda_ib_operations
Linda Infiniband operations.
Definition linda.c:1484
static int linda_set_serdes_param(struct linda *linda, struct linda_serdes_param *param)
Program IB SerDes register(s)
Definition linda.c:1998
static int linda_ib_epb_wait(struct linda *linda, struct QIB_7220_ibsd_epb_transaction_reg *xact)
Wait for IB external parallel bus transaction to complete.
Definition linda.c:1708
static int linda_ib_epb_ram_xfer(struct linda *linda, unsigned int address, const void *write, void *read, size_t len)
Transfer data to/from microcontroller RAM.
Definition linda.c:1887
static unsigned long linda_send_buffer_offset(struct linda *linda, unsigned int send_buf)
Calculate starting offset for send buffer.
Definition linda.c:444
static int linda_ctx_to_qpn(unsigned int ctx)
Map context number to QPN.
Definition linda.c:316
static int linda_init_i2c(struct linda *linda)
Initialise Linda I2C subsystem.
Definition linda.c:1596
static int linda_create_recv_wq(struct linda *linda, struct ib_queue_pair *qp)
Create receive work queue.
Definition linda.c:597
static void linda_poll_recv_wq(struct ib_device *ibdev, struct ib_queue_pair *qp)
Poll receive work queue.
Definition linda.c:1318
static int linda_modify_qp(struct ib_device *ibdev, struct ib_queue_pair *qp)
Modify queue pair.
Definition linda.c:889
#define LINDA_SEND_BUF_TOGGLE
Send buffer toggle bit.
Definition linda.c:379
static struct linda_serdes_param linda_serdes_defaults3[]
Definition linda.c:2124
static void linda_ib_epb_release(struct linda *linda)
Release ownership of the IB external parallel bus.
Definition linda.c:1740
static void linda_fini_send(struct linda *linda)
Shut down send datapath.
Definition linda.c:569
#define LINDA_EPB_ALL_CHANNELS
Magic "all channels" channel number.
Definition linda.c:1986
static int linda_qpn_to_ctx(unsigned int qpn)
Map QPN to context number.
Definition linda.c:327
static int linda_probe(struct pci_device *pci)
Probe PCI device.
Definition linda.c:2317
static int linda_verify_uc_ram(struct linda *linda)
Verify the microcontroller RAM.
Definition linda.c:2156
static void linda_remove(struct pci_device *pci)
Remove PCI device.
Definition linda.c:2411
static int linda_create_cq(struct ib_device *ibdev, struct ib_completion_queue *cq)
Create completion queue.
Definition linda.c:797
static void linda_destroy_recv_wq(struct linda *linda, struct ib_queue_pair *qp)
Destroy receive work queue.
Definition linda.c:665
static int linda_alloc_ctx(struct linda *linda)
Allocate a context.
Definition linda.c:338
static int linda_set_serdes_params(struct linda *linda, struct linda_serdes_param *params)
Program IB SerDes registers.
Definition linda.c:2038
#define linda_writeq_array8b(_linda, _ptr, _offset, _idx)
Definition linda.c:149
static int linda_ib_epb_request(struct linda *linda)
Request ownership of the IB external parallel bus.
Definition linda.c:1678
static struct bit_basher_operations linda_i2c_basher_ops
Linda I2C bit-bashing interface operations.
Definition linda.c:1585
static int linda_init_recv(struct linda *linda)
Initialise receive datapath.
Definition linda.c:695
static const char * linda_link_state_text(unsigned int link_state)
Textual representation of link state.
Definition linda.c:179
static int linda_trim_ib(struct linda *linda)
Use the microcontroller to trim the IB link.
Definition linda.c:2191
QLogic Linda Infiniband HCA.
#define LINDA_RECV_HEADER_COUNT
Number of RX headers per context.
Definition linda.h:193
@ LINDA_EAGER_BUFFER_16K
Definition linda.h:184
@ LINDA_EAGER_BUFFER_4K
Definition linda.h:182
@ LINDA_EAGER_BUFFER_NONE
Definition linda.h:180
@ LINDA_EAGER_BUFFER_8K
Definition linda.h:183
@ LINDA_EAGER_BUFFER_64K
Definition linda.h:186
@ LINDA_EAGER_BUFFER_2K
Definition linda.h:181
@ LINDA_EAGER_BUFFER_32K
Definition linda.h:185
#define LINDA_EPB_LOC_ADDRESS(_loc)
Definition linda.h:249
#define LINDA_EPB_UC_DATA
Definition linda.h:261
#define LINDA_EAGER_ARRAY_SIZE_5CTX_0
PortCfg values for different numbers of contexts.
Definition linda.h:168
#define LINDA_EEPROM_SERIAL_SIZE
Board serial number size within EEPROM.
Definition linda.h:142
#define LINDA_EAGER_BUFFER_ALIGN
Eager buffer required alignment.
Definition linda.h:176
#define LINDA_EPB_LOC(_cs, _channel, _element, _reg)
Linda external parallel bus locations.
Definition linda.h:247
#define LINDA_EEPROM_SERIAL_OFFSET
Board serial number offset within EEPROM.
Definition linda.h:139
#define LINDA_RECV_PAYLOAD_SIZE
RX payload size.
Definition linda.h:212
#define LINDA_EPB_UC_CHUNK_SIZE
Definition linda.h:262
#define LINDA_MAX_SEND_BUFS
Maximum number of send buffers used.
Definition linda.h:149
#define LINDA_EPB_REQUEST_MAX_WAIT_US
Maximum time for wait for external parallel bus request, in us.
Definition linda.h:222
#define LINDA_EPB_UC_ADDR_LO
Definition linda.h:259
#define LINDA_QP_IDETH
QPN used for Infinipath Packets.
Definition linda.h:219
#define LINDA_EPB_UC_CTL_WRITE
Definition linda.h:257
#define LINDA_NUM_CONTEXTS
Number of contexts (including kernel context)
Definition linda.h:158
@ LINDA_PORTCFG_5CTX
Definition linda.h:162
@ LINDA_PORTCFG_17CTX
Definition linda.h:164
@ LINDA_PORTCFG_9CTX
Definition linda.h:163
#define LINDA_GPIO_SDA
Linda I2C SDA line GPIO number.
Definition linda.h:130
#define LINDA_EPB_ADDRESS_REG(_address)
Definition linda.h:240
uint8_t linda_ib_fw[8192]
Definition linda_fw.c:44
#define LINDA_EAGER_ARRAY_SIZE_17CTX_OTHER
Definition linda.h:173
#define LINDA_EPB_ADDRESS_ELEMENT(_address)
Definition linda.h:239
#define LINDA_SEND_BUF_SIZE
Linda send buffer size.
Definition linda.h:152
#define LINDA_EPB_ADDRESS_CHANNEL(_address)
Definition linda.h:238
#define LINDA_EEPROM_GUID_OFFSET
GUID offset within EEPROM.
Definition linda.h:133
#define LINDA_EPB_UC_CTL_READ
Definition linda.h:258
#define LINDA_EPB_UC_CTL
Definition linda.h:256
#define LINDA_EAGER_ARRAY_SIZE_5CTX_OTHER
Definition linda.h:169
#define LINDA_EPB_ADDRESS(_channel, _element, _reg)
Linda external parallel bus register addresses.
Definition linda.h:236
#define LINDA_EPB_LOC_CS(_loc)
Definition linda.h:250
#define LINDA_EPB_XACT_MAX_WAIT_US
Maximum time for wait for external parallel bus transaction, in us.
Definition linda.h:225
#define LINDA_EPB_UC_ADDR_HI
Definition linda.h:260
#define LINDA_BAR0_SIZE
Linda memory BAR size.
Definition linda.h:124
#define LINDA_EPB_CS_SERDES
Linda external parallel bus chip selects.
Definition linda.h:228
#define LINDA_EPB_READ
Definition linda.h:233
#define LINDA_RECV_HEADER_SIZE
Maximum size of each RX header.
Definition linda.h:199
#define LINDA_RECV_HEADERS_SIZE
Total size of an RX header ring.
Definition linda.h:202
#define LINDA_SENDBUFAVAIL_ALIGN
DMA alignment for send buffer availability.
Definition linda.h:85
#define LINDA_TRIM_DONE_MAX_WAIT_MS
Maximum time to wait for "trim done" signal, in ms.
Definition linda.h:267
#define LINDA_EAGER_ARRAY_SIZE_17CTX_0
Definition linda.h:172
#define LINDA_EAGER_ARRAY_SIZE_9CTX_0
Definition linda.h:170
#define LINDA_LINK_STATE_MAX_WAIT_US
Maximum time to wait for link state changes, in us.
Definition linda.h:279
@ LINDA_LINK_STATE_DOWN
Definition linda.h:271
@ LINDA_LINK_STATE_ARM
Definition linda.h:273
@ LINDA_LINK_STATE_INIT
Definition linda.h:272
@ LINDA_LINK_STATE_ACT_DEFER
Definition linda.h:275
@ LINDA_LINK_STATE_ACTIVE
Definition linda.h:274
#define LINDA_RECV_HEADERS_ALIGN
RX header alignment.
Definition linda.h:206
#define LINDA_EPB_WRITE
Linda external parallel bus read/write operations.
Definition linda.h:232
#define LINDA_GPIO_SCL
Linda I2C SCL line GPIO number.
Definition linda.h:127
#define LINDA_EAGER_ARRAY_SIZE_9CTX_OTHER
Definition linda.h:171
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition list.h:432
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
void * malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition malloc.c:707
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition malloc.c:723
Dynamic memory allocation.
uint32_t control
Control.
Definition myson.h:3
static unsigned int unsigned int reg
Definition myson.h:162
uint32_t channel
RNDIS channel.
Definition netvsc.h:3
struct option_descriptor read[1]
Definition nvo_cmd.c:116
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition pci.c:241
PCI bus.
#define __pci_driver
Declare a PCI driver.
Definition pci.h:278
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition pci.h:366
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition pci.h:308
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition pci.h:376
#define BIT_GET(_ptr, _field)
Extract value of named field (for fields up to the size of a long)
Definition pseudobit.h:235
#define BIT_FILL_3(_ptr, _field1,...)
Definition pseudobit.h:195
#define BIT_SET(_ptr, _field, _value)
Definition pseudobit.h:238
#define BIT_FILL_4(_ptr, _field1,...)
Definition pseudobit.h:200
#define BIT_FILL_2(_ptr, _field1,...)
Definition pseudobit.h:190
#define BIT_FILL_6(_ptr, _field1,...)
Definition pseudobit.h:210
#define BIT_FILL_1(_ptr, _field1,...)
Definition pseudobit.h:185
#define QIB_7220_ibsd_epb_transaction_reg_offset
#define QIB_7220_ErrStatus_offset
#define QIB_7220_RcvEgrBase_offset
#define QIB_7220_IBSerDesCtrl_offset
#define QIB_7220_IntStatus_offset
#define QIB_7220_RcvHdrCnt_offset
#define QIB_7220_IBCDDRCtrl_offset
#define QIB_7220_SendBufBase_offset
#define QIB_7220_ibsd_epb_access_ctrl_offset
#define QIB_7220_GPIOOut_offset
#define QIB_7220_IBCStatus_offset
#define QIB_7220_RcvHdrHead0_offset
#define QIB_7220_EXTCtrl_offset
#define QIB_7220_EXTStatus_offset
#define QIB_7220_RcvHdrTailAddr0_offset
#define QIB_7220_XGXSCfg_offset
#define QIB_7220_IBCCtrl_offset
#define QIB_7220_SendBufAvailAddr_offset
#define QIB_7220_RcvHdrEntSize_offset
#define QIB_7220_RcvEgrIndexHead0_offset
#define QIB_7220_RcvHdrAddr0_offset
#define QIB_7220_RcvBTHQP_offset
#define QIB_7220_ErrClear_offset
#define QIB_7220_Control_offset
#define QIB_7220_Revision_offset
#define QIB_7220_SendCtrl_offset
#define QIB_7220_RcvCtrl_offset
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
unsigned long int dword
Definition smc9000.h:40
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
Bit-bashing operations.
Definition bitbash.h:16
A bit-bashing interface.
Definition bitbash.h:56
A bit-bashing I2C interface.
Definition i2c.h:91
struct i2c_interface i2c
I2C interface.
Definition i2c.h:93
struct bit_basher basher
Bit-bashing interface.
Definition i2c.h:95
An I2C device.
Definition i2c.h:20
An I2C interface.
Definition i2c.h:57
int(* read)(struct i2c_interface *i2c, struct i2c_device *i2cdev, unsigned int offset, uint8_t *data, unsigned int len)
Read data from I2C device.
Definition i2c.h:68
An Infiniband Address Vector.
Definition infiniband.h:73
An Infiniband Completion Queue.
Definition infiniband.h:225
unsigned long cqn
Completion queue number.
Definition infiniband.h:231
struct list_head work_queues
List of work queues completing to this queue.
Definition infiniband.h:243
Infiniband device operations.
Definition infiniband.h:255
An Infiniband device.
Definition infiniband.h:399
uint8_t link_width_enabled
Link width enabled.
Definition infiniband.h:430
uint8_t link_speed_active
Link speed active.
Definition infiniband.h:438
unsigned int ports
Total ports on device.
Definition infiniband.h:421
uint8_t link_speed_supported
Link speed supported.
Definition infiniband.h:434
struct ib_device_operations * op
Infiniband operations.
Definition infiniband.h:417
union ib_guid node_guid
Node GUID.
Definition infiniband.h:440
struct device * dev
Underlying device.
Definition infiniband.h:411
uint8_t link_width_active
Link width active.
Definition infiniband.h:432
uint8_t link_speed_enabled
Link speed enabled.
Definition infiniband.h:436
uint8_t link_width_supported
Link width supported.
Definition infiniband.h:428
uint8_t port_state
Port state.
Definition infiniband.h:426
union ib_gid gid
Port GID (comprising GID prefix and port GUID)
Definition infiniband.h:442
unsigned int port
Port number.
Definition infiniband.h:419
A Port Information attribute.
Definition ib_mad.h:105
An Infiniband Queue Pair.
Definition infiniband.h:158
struct ib_work_queue recv
Receive queue.
Definition infiniband.h:181
unsigned long qpn
Queue pair number.
Definition infiniband.h:166
An Infiniband Work Queue.
Definition infiniband.h:101
unsigned int fill
Number of occupied work queue entries.
Definition infiniband.h:115
struct io_buffer ** iobufs
I/O buffers assigned to work queue.
Definition infiniband.h:125
struct ib_completion_queue * cq
Associated completion queue.
Definition infiniband.h:107
struct list_head list
List of work queues on this completion queue.
Definition infiniband.h:109
struct ib_queue_pair * qp
Containing queue pair.
Definition infiniband.h:103
int is_send
"Is a send queue" flag
Definition infiniband.h:105
unsigned int num_wqes
Number of work queue entries.
Definition infiniband.h:113
A persistent I/O buffer.
Definition iobuf.h:38
void * data
Start of data.
Definition iobuf.h:53
A Linda receive work queue.
Definition linda.c:59
unsigned int eager_prod
Eager array producer index.
Definition linda.c:71
struct QIB_7220_scalar header_prod
Receive header producer offset (written by hardware)
Definition linda.c:63
unsigned int eager_entries
Number of entries in eager array.
Definition linda.c:69
unsigned long eager_array
Offset within register space of the eager array.
Definition linda.c:67
void * header
Receive header ring.
Definition linda.c:61
unsigned int eager_cons
Eager array consumer index.
Definition linda.c:73
unsigned int header_cons
Receive header consumer offset.
Definition linda.c:65
A Linda send work queue.
Definition linda.c:49
unsigned int cons
Consumer index.
Definition linda.c:55
unsigned int prod
Producer index.
Definition linda.c:53
uint8_t * send_buf
Send buffer usage.
Definition linda.c:51
A Linda SerDes parameter.
Definition linda.c:1976
uint16_t address
EPB address as constructed by LINDA_EPB_ADDRESS()
Definition linda.c:1978
uint8_t mask
Mask to apply to old value.
Definition linda.c:1982
uint8_t value
Value to set.
Definition linda.c:1980
A Linda HCA.
Definition linda.c:77
void * regs
Registers.
Definition linda.c:79
struct QIB_7220_SendBufAvail * sendbufavail
Send buffer availability (reported by hardware)
Definition linda.c:91
struct i2c_bit_basher i2c
I2C bit-bashing interface.
Definition linda.c:102
uint8_t used_ctx[LINDA_NUM_CONTEXTS]
In-use contexts.
Definition linda.c:82
uint8_t send_buf[LINDA_MAX_SEND_BUFS]
Send buffer availability (maintained by software)
Definition linda.c:93
struct linda_recv_work_queue recv_wq[LINDA_NUM_CONTEXTS]
Receive work queues.
Definition linda.c:86
unsigned int reserved_send_bufs
Number of reserved send buffers (across all QPs)
Definition linda.c:99
unsigned long send_buffer_base
Offset within register space of the first send buffer.
Definition linda.c:89
struct linda_send_work_queue send_wq[LINDA_NUM_CONTEXTS]
Send work queues.
Definition linda.c:84
unsigned int send_buf_cons
Send buffer availability consumer counter.
Definition linda.c:97
struct i2c_device eeprom
I2C serial EEPROM.
Definition linda.c:104
unsigned int send_buf_prod
Send buffer availability producer counter.
Definition linda.c:95
A PCI device ID list entry.
Definition pci.h:175
A PCI device.
Definition pci.h:211
unsigned long membase
Memory base.
Definition pci.h:220
struct device dev
Generic device.
Definition pci.h:213
A PCI driver.
Definition pci.h:252
int(* probe)(struct pci_device *pci)
Probe device.
Definition pci.h:265
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition timer.c:61
An Infiniband Global Identifier.
Definition ib_packet.h:34
struct ib_gid::@251011351113275240012301235177256303262052134237 s
union ib_guid guid
Definition ib_packet.h:41
An Infiniband Globally Unique Identifier.
Definition ib_packet.h:19
A management datagram.
Definition ib_mad.h:611
#define writel
Definition w89c840.c:160
static struct xen_remove_from_physmap * remove
Definition xenmem.h:40