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