2
* Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
3
* Copyright (C) 2008 Mellanox Technologies Ltd.
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or any later version.
10
* This program is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
FILE_LICENCE ( GPL2_OR_LATER );
33
#include <ipxe/pcibackup.h>
34
#include <ipxe/malloc.h>
35
#include <ipxe/umalloc.h>
36
#include <ipxe/iobuf.h>
37
#include <ipxe/netdevice.h>
38
#include <ipxe/infiniband.h>
39
#include <ipxe/ib_smc.h>
40
#include <ipxe/if_ether.h>
41
#include <ipxe/ethernet.h>
42
#include <ipxe/fcoe.h>
43
#include <ipxe/vlan.h>
44
#include <ipxe/bofm.h>
45
#include <ipxe/nvsvpd.h>
52
* Mellanox Hermon Infiniband HCA
56
/***************************************************************************
58
* Queue number allocation
60
***************************************************************************
64
* Allocate offsets within usage bitmask
66
* @v bits Usage bitmask
67
* @v bits_len Length of usage bitmask
68
* @v num_bits Number of contiguous bits to allocate within bitmask
69
* @ret bit First free bit within bitmask, or negative error
71
static int hermon_bitmask_alloc ( hermon_bitmask_t *bits,
72
unsigned int bits_len,
73
unsigned int num_bits ) {
75
hermon_bitmask_t mask = 1;
76
unsigned int found = 0;
78
/* Search bits for num_bits contiguous free bits */
79
while ( bit < bits_len ) {
80
if ( ( mask & *bits ) == 0 ) {
81
if ( ++found == num_bits )
87
mask = ( mask << 1 ) | ( mask >> ( 8 * sizeof ( mask ) - 1 ) );
94
/* Mark bits as in-use */
99
mask = ( mask >> 1 ) | ( mask << ( 8 * sizeof ( mask ) - 1 ) );
102
return ( bit - num_bits + 1 );
106
* Free offsets within usage bitmask
108
* @v bits Usage bitmask
109
* @v bit Starting bit within bitmask
110
* @v num_bits Number of contiguous bits to free within bitmask
112
static void hermon_bitmask_free ( hermon_bitmask_t *bits,
113
int bit, unsigned int num_bits ) {
114
hermon_bitmask_t mask;
116
for ( ; num_bits ; bit++, num_bits-- ) {
117
mask = ( 1 << ( bit % ( 8 * sizeof ( mask ) ) ) );
118
bits[ ( bit / ( 8 * sizeof ( mask ) ) ) ] &= ~mask;
122
/***************************************************************************
126
***************************************************************************
130
* Wait for Hermon command completion
132
* @v hermon Hermon device
133
* @v hcr HCA command registers
134
* @ret rc Return status code
136
static int hermon_cmd_wait ( struct hermon *hermon,
137
struct hermonprm_hca_command_register *hcr ) {
140
for ( wait = HERMON_HCR_MAX_WAIT_MS ; wait ; wait-- ) {
142
readl ( hermon->config + HERMON_HCR_REG ( 6 ) );
143
if ( ( MLX_GET ( hcr, go ) == 0 ) &&
144
( MLX_GET ( hcr, t ) == hermon->toggle ) )
154
* @v hermon Hermon device
155
* @v command Command opcode, flags and input/output lengths
156
* @v op_mod Opcode modifier (0 if no modifier applicable)
157
* @v in Input parameters
158
* @v in_mod Input modifier (0 if no modifier applicable)
159
* @v out Output parameters
160
* @ret rc Return status code
162
static int hermon_cmd ( struct hermon *hermon, unsigned long command,
163
unsigned int op_mod, const void *in,
164
unsigned int in_mod, void *out ) {
165
struct hermonprm_hca_command_register hcr;
166
unsigned int opcode = HERMON_HCR_OPCODE ( command );
167
size_t in_len = HERMON_HCR_IN_LEN ( command );
168
size_t out_len = HERMON_HCR_OUT_LEN ( command );
175
assert ( in_len <= HERMON_MBOX_SIZE );
176
assert ( out_len <= HERMON_MBOX_SIZE );
178
DBGC2 ( hermon, "Hermon %p command %02x in %zx%s out %zx%s\n",
179
hermon, opcode, in_len,
180
( ( command & HERMON_HCR_IN_MBOX ) ? "(mbox)" : "" ), out_len,
181
( ( command & HERMON_HCR_OUT_MBOX ) ? "(mbox)" : "" ) );
183
/* Check that HCR is free */
184
if ( ( rc = hermon_cmd_wait ( hermon, &hcr ) ) != 0 ) {
185
DBGC ( hermon, "Hermon %p command interface locked\n",
190
/* Flip HCR toggle */
191
hermon->toggle = ( 1 - hermon->toggle );
194
memset ( &hcr, 0, sizeof ( hcr ) );
195
in_buffer = &hcr.u.dwords[0];
196
if ( in_len && ( command & HERMON_HCR_IN_MBOX ) ) {
197
memset ( hermon->mailbox_in, 0, HERMON_MBOX_SIZE );
198
in_buffer = hermon->mailbox_in;
199
MLX_FILL_H ( &hcr, 0, in_param_h, virt_to_bus ( in_buffer ) );
200
MLX_FILL_1 ( &hcr, 1, in_param_l, virt_to_bus ( in_buffer ) );
202
memcpy ( in_buffer, in, in_len );
203
MLX_FILL_1 ( &hcr, 2, input_modifier, in_mod );
204
out_buffer = &hcr.u.dwords[3];
205
if ( out_len && ( command & HERMON_HCR_OUT_MBOX ) ) {
206
out_buffer = hermon->mailbox_out;
207
MLX_FILL_H ( &hcr, 3, out_param_h,
208
virt_to_bus ( out_buffer ) );
209
MLX_FILL_1 ( &hcr, 4, out_param_l,
210
virt_to_bus ( out_buffer ) );
212
MLX_FILL_4 ( &hcr, 6,
214
opcode_modifier, op_mod,
217
DBGC ( hermon, "Hermon %p issuing command %04x\n",
219
DBGC2_HDA ( hermon, virt_to_phys ( hermon->config + HERMON_HCR_BASE ),
220
&hcr, sizeof ( hcr ) );
221
if ( in_len && ( command & HERMON_HCR_IN_MBOX ) ) {
222
DBGC2 ( hermon, "Input mailbox:\n" );
223
DBGC2_HDA ( hermon, virt_to_phys ( in_buffer ), in_buffer,
224
( ( in_len < 512 ) ? in_len : 512 ) );
228
for ( i = 0 ; i < ( sizeof ( hcr ) / sizeof ( hcr.u.dwords[0] ) ) ;
230
writel ( hcr.u.dwords[i],
231
hermon->config + HERMON_HCR_REG ( i ) );
235
/* Wait for command completion */
236
if ( ( rc = hermon_cmd_wait ( hermon, &hcr ) ) != 0 ) {
237
DBGC ( hermon, "Hermon %p timed out waiting for command:\n",
240
virt_to_phys ( hermon->config + HERMON_HCR_BASE ),
241
&hcr, sizeof ( hcr ) );
245
/* Check command status */
246
status = MLX_GET ( &hcr, status );
248
DBGC ( hermon, "Hermon %p command failed with status %02x:\n",
251
virt_to_phys ( hermon->config + HERMON_HCR_BASE ),
252
&hcr, sizeof ( hcr ) );
256
/* Read output parameters, if any */
257
hcr.u.dwords[3] = readl ( hermon->config + HERMON_HCR_REG ( 3 ) );
258
hcr.u.dwords[4] = readl ( hermon->config + HERMON_HCR_REG ( 4 ) );
259
memcpy ( out, out_buffer, out_len );
261
DBGC2 ( hermon, "Output%s:\n",
262
( command & HERMON_HCR_OUT_MBOX ) ? " mailbox" : "" );
263
DBGC2_HDA ( hermon, virt_to_phys ( out_buffer ), out_buffer,
264
( ( out_len < 512 ) ? out_len : 512 ) );
271
hermon_cmd_query_dev_cap ( struct hermon *hermon,
272
struct hermonprm_query_dev_cap *dev_cap ) {
273
return hermon_cmd ( hermon,
274
HERMON_HCR_OUT_CMD ( HERMON_HCR_QUERY_DEV_CAP,
275
1, sizeof ( *dev_cap ) ),
276
0, NULL, 0, dev_cap );
280
hermon_cmd_query_fw ( struct hermon *hermon, struct hermonprm_query_fw *fw ) {
281
return hermon_cmd ( hermon,
282
HERMON_HCR_OUT_CMD ( HERMON_HCR_QUERY_FW,
288
hermon_cmd_init_hca ( struct hermon *hermon,
289
const struct hermonprm_init_hca *init_hca ) {
290
return hermon_cmd ( hermon,
291
HERMON_HCR_IN_CMD ( HERMON_HCR_INIT_HCA,
292
1, sizeof ( *init_hca ) ),
293
0, init_hca, 0, NULL );
297
hermon_cmd_close_hca ( struct hermon *hermon ) {
298
return hermon_cmd ( hermon,
299
HERMON_HCR_VOID_CMD ( HERMON_HCR_CLOSE_HCA ),
304
hermon_cmd_init_port ( struct hermon *hermon, unsigned int port ) {
305
return hermon_cmd ( hermon,
306
HERMON_HCR_VOID_CMD ( HERMON_HCR_INIT_PORT ),
307
0, NULL, port, NULL );
311
hermon_cmd_close_port ( struct hermon *hermon, unsigned int port ) {
312
return hermon_cmd ( hermon,
313
HERMON_HCR_VOID_CMD ( HERMON_HCR_CLOSE_PORT ),
314
0, NULL, port, NULL );
318
hermon_cmd_set_port ( struct hermon *hermon, int is_ethernet,
319
unsigned int port_selector,
320
const union hermonprm_set_port *set_port ) {
321
return hermon_cmd ( hermon,
322
HERMON_HCR_IN_CMD ( HERMON_HCR_SET_PORT,
323
1, sizeof ( *set_port ) ),
324
is_ethernet, set_port, port_selector, NULL );
328
hermon_cmd_sw2hw_mpt ( struct hermon *hermon, unsigned int index,
329
const struct hermonprm_mpt *mpt ) {
330
return hermon_cmd ( hermon,
331
HERMON_HCR_IN_CMD ( HERMON_HCR_SW2HW_MPT,
332
1, sizeof ( *mpt ) ),
333
0, mpt, index, NULL );
337
hermon_cmd_write_mtt ( struct hermon *hermon,
338
const struct hermonprm_write_mtt *write_mtt ) {
339
return hermon_cmd ( hermon,
340
HERMON_HCR_IN_CMD ( HERMON_HCR_WRITE_MTT,
341
1, sizeof ( *write_mtt ) ),
342
0, write_mtt, 1, NULL );
346
hermon_cmd_map_eq ( struct hermon *hermon, unsigned long index_map,
347
const struct hermonprm_event_mask *mask ) {
348
return hermon_cmd ( hermon,
349
HERMON_HCR_IN_CMD ( HERMON_HCR_MAP_EQ,
350
0, sizeof ( *mask ) ),
351
0, mask, index_map, NULL );
355
hermon_cmd_sw2hw_eq ( struct hermon *hermon, unsigned int index,
356
const struct hermonprm_eqc *eqctx ) {
357
return hermon_cmd ( hermon,
358
HERMON_HCR_IN_CMD ( HERMON_HCR_SW2HW_EQ,
359
1, sizeof ( *eqctx ) ),
360
0, eqctx, index, NULL );
364
hermon_cmd_hw2sw_eq ( struct hermon *hermon, unsigned int index,
365
struct hermonprm_eqc *eqctx ) {
366
return hermon_cmd ( hermon,
367
HERMON_HCR_OUT_CMD ( HERMON_HCR_HW2SW_EQ,
368
1, sizeof ( *eqctx ) ),
369
1, NULL, index, eqctx );
373
hermon_cmd_query_eq ( struct hermon *hermon, unsigned int index,
374
struct hermonprm_eqc *eqctx ) {
375
return hermon_cmd ( hermon,
376
HERMON_HCR_OUT_CMD ( HERMON_HCR_QUERY_EQ,
377
1, sizeof ( *eqctx ) ),
378
0, NULL, index, eqctx );
382
hermon_cmd_sw2hw_cq ( struct hermon *hermon, unsigned long cqn,
383
const struct hermonprm_completion_queue_context *cqctx ){
384
return hermon_cmd ( hermon,
385
HERMON_HCR_IN_CMD ( HERMON_HCR_SW2HW_CQ,
386
1, sizeof ( *cqctx ) ),
387
0, cqctx, cqn, NULL );
391
hermon_cmd_hw2sw_cq ( struct hermon *hermon, unsigned long cqn,
392
struct hermonprm_completion_queue_context *cqctx ) {
393
return hermon_cmd ( hermon,
394
HERMON_HCR_OUT_CMD ( HERMON_HCR_HW2SW_CQ,
395
1, sizeof ( *cqctx ) ),
396
0, NULL, cqn, cqctx );
400
hermon_cmd_query_cq ( struct hermon *hermon, unsigned long cqn,
401
struct hermonprm_completion_queue_context *cqctx ) {
402
return hermon_cmd ( hermon,
403
HERMON_HCR_OUT_CMD ( HERMON_HCR_QUERY_CQ,
404
1, sizeof ( *cqctx ) ),
405
0, NULL, cqn, cqctx );
409
hermon_cmd_rst2init_qp ( struct hermon *hermon, unsigned long qpn,
410
const struct hermonprm_qp_ee_state_transitions *ctx ){
411
return hermon_cmd ( hermon,
412
HERMON_HCR_IN_CMD ( HERMON_HCR_RST2INIT_QP,
413
1, sizeof ( *ctx ) ),
418
hermon_cmd_init2rtr_qp ( struct hermon *hermon, unsigned long qpn,
419
const struct hermonprm_qp_ee_state_transitions *ctx ){
420
return hermon_cmd ( hermon,
421
HERMON_HCR_IN_CMD ( HERMON_HCR_INIT2RTR_QP,
422
1, sizeof ( *ctx ) ),
427
hermon_cmd_rtr2rts_qp ( struct hermon *hermon, unsigned long qpn,
428
const struct hermonprm_qp_ee_state_transitions *ctx ) {
429
return hermon_cmd ( hermon,
430
HERMON_HCR_IN_CMD ( HERMON_HCR_RTR2RTS_QP,
431
1, sizeof ( *ctx ) ),
436
hermon_cmd_rts2rts_qp ( struct hermon *hermon, unsigned long qpn,
437
const struct hermonprm_qp_ee_state_transitions *ctx ) {
438
return hermon_cmd ( hermon,
439
HERMON_HCR_IN_CMD ( HERMON_HCR_RTS2RTS_QP,
440
1, sizeof ( *ctx ) ),
445
hermon_cmd_2rst_qp ( struct hermon *hermon, unsigned long qpn ) {
446
return hermon_cmd ( hermon,
447
HERMON_HCR_VOID_CMD ( HERMON_HCR_2RST_QP ),
448
0x03, NULL, qpn, NULL );
452
hermon_cmd_query_qp ( struct hermon *hermon, unsigned long qpn,
453
struct hermonprm_qp_ee_state_transitions *ctx ) {
454
return hermon_cmd ( hermon,
455
HERMON_HCR_OUT_CMD ( HERMON_HCR_QUERY_QP,
456
1, sizeof ( *ctx ) ),
461
hermon_cmd_conf_special_qp ( struct hermon *hermon, unsigned int internal_qps,
462
unsigned long base_qpn ) {
463
return hermon_cmd ( hermon,
464
HERMON_HCR_VOID_CMD ( HERMON_HCR_CONF_SPECIAL_QP ),
465
internal_qps, NULL, base_qpn, NULL );
469
hermon_cmd_mad_ifc ( struct hermon *hermon, unsigned int port,
470
union hermonprm_mad *mad ) {
471
return hermon_cmd ( hermon,
472
HERMON_HCR_INOUT_CMD ( HERMON_HCR_MAD_IFC,
474
1, sizeof ( *mad ) ),
475
0x03, mad, port, mad );
479
hermon_cmd_read_mcg ( struct hermon *hermon, unsigned int index,
480
struct hermonprm_mcg_entry *mcg ) {
481
return hermon_cmd ( hermon,
482
HERMON_HCR_OUT_CMD ( HERMON_HCR_READ_MCG,
483
1, sizeof ( *mcg ) ),
484
0, NULL, index, mcg );
488
hermon_cmd_write_mcg ( struct hermon *hermon, unsigned int index,
489
const struct hermonprm_mcg_entry *mcg ) {
490
return hermon_cmd ( hermon,
491
HERMON_HCR_IN_CMD ( HERMON_HCR_WRITE_MCG,
492
1, sizeof ( *mcg ) ),
493
0, mcg, index, NULL );
497
hermon_cmd_mgid_hash ( struct hermon *hermon, const union ib_gid *gid,
498
struct hermonprm_mgm_hash *hash ) {
499
return hermon_cmd ( hermon,
500
HERMON_HCR_INOUT_CMD ( HERMON_HCR_MGID_HASH,
502
0, sizeof ( *hash ) ),
507
hermon_cmd_mod_stat_cfg ( struct hermon *hermon, unsigned int mode,
508
unsigned int input_mod,
509
struct hermonprm_scalar_parameter *portion ) {
510
return hermon_cmd ( hermon,
511
HERMON_HCR_INOUT_CMD ( HERMON_HCR_MOD_STAT_CFG,
512
0, sizeof ( *portion ),
513
0, sizeof ( *portion ) ),
514
mode, portion, input_mod, portion );
518
hermon_cmd_query_port ( struct hermon *hermon, unsigned int port,
519
struct hermonprm_query_port_cap *query_port ) {
520
return hermon_cmd ( hermon,
521
HERMON_HCR_OUT_CMD ( HERMON_HCR_QUERY_PORT,
522
1, sizeof ( *query_port ) ),
523
0, NULL, port, query_port );
527
hermon_cmd_sense_port ( struct hermon *hermon, unsigned int port,
528
struct hermonprm_sense_port *port_type ) {
529
return hermon_cmd ( hermon,
530
HERMON_HCR_OUT_CMD ( HERMON_HCR_SENSE_PORT,
531
0, sizeof ( *port_type ) ),
532
0, NULL, port, port_type );
536
hermon_cmd_run_fw ( struct hermon *hermon ) {
537
return hermon_cmd ( hermon,
538
HERMON_HCR_VOID_CMD ( HERMON_HCR_RUN_FW ),
543
hermon_cmd_unmap_icm ( struct hermon *hermon, unsigned int page_count,
544
const struct hermonprm_scalar_parameter *offset ) {
545
return hermon_cmd ( hermon,
546
HERMON_HCR_IN_CMD ( HERMON_HCR_UNMAP_ICM,
547
0, sizeof ( *offset ) ),
548
0, offset, page_count, NULL );
552
hermon_cmd_map_icm ( struct hermon *hermon,
553
const struct hermonprm_virtual_physical_mapping *map ) {
554
return hermon_cmd ( hermon,
555
HERMON_HCR_IN_CMD ( HERMON_HCR_MAP_ICM,
556
1, sizeof ( *map ) ),
561
hermon_cmd_unmap_icm_aux ( struct hermon *hermon ) {
562
return hermon_cmd ( hermon,
563
HERMON_HCR_VOID_CMD ( HERMON_HCR_UNMAP_ICM_AUX ),
568
hermon_cmd_map_icm_aux ( struct hermon *hermon,
569
const struct hermonprm_virtual_physical_mapping *map ) {
570
return hermon_cmd ( hermon,
571
HERMON_HCR_IN_CMD ( HERMON_HCR_MAP_ICM_AUX,
572
1, sizeof ( *map ) ),
577
hermon_cmd_set_icm_size ( struct hermon *hermon,
578
const struct hermonprm_scalar_parameter *icm_size,
579
struct hermonprm_scalar_parameter *icm_aux_size ) {
580
return hermon_cmd ( hermon,
581
HERMON_HCR_INOUT_CMD ( HERMON_HCR_SET_ICM_SIZE,
582
0, sizeof ( *icm_size ),
583
0, sizeof (*icm_aux_size) ),
584
0, icm_size, 0, icm_aux_size );
588
hermon_cmd_unmap_fa ( struct hermon *hermon ) {
589
return hermon_cmd ( hermon,
590
HERMON_HCR_VOID_CMD ( HERMON_HCR_UNMAP_FA ),
595
hermon_cmd_map_fa ( struct hermon *hermon,
596
const struct hermonprm_virtual_physical_mapping *map ) {
597
return hermon_cmd ( hermon,
598
HERMON_HCR_IN_CMD ( HERMON_HCR_MAP_FA,
599
1, sizeof ( *map ) ),
603
/***************************************************************************
605
* Memory translation table operations
607
***************************************************************************
611
* Allocate MTT entries
613
* @v hermon Hermon device
614
* @v memory Memory to map into MTT
615
* @v len Length of memory to map
616
* @v mtt MTT descriptor to fill in
617
* @ret rc Return status code
619
static int hermon_alloc_mtt ( struct hermon *hermon,
620
const void *memory, size_t len,
621
struct hermon_mtt *mtt ) {
622
struct hermonprm_write_mtt write_mtt;
625
unsigned int page_offset;
626
unsigned int num_pages;
628
unsigned int mtt_base_addr;
632
/* Find available MTT entries */
633
start = virt_to_phys ( memory );
634
page_offset = ( start & ( HERMON_PAGE_SIZE - 1 ) );
635
start -= page_offset;
637
num_pages = ( ( len + HERMON_PAGE_SIZE - 1 ) / HERMON_PAGE_SIZE );
638
mtt_offset = hermon_bitmask_alloc ( hermon->mtt_inuse, HERMON_MAX_MTTS,
640
if ( mtt_offset < 0 ) {
641
DBGC ( hermon, "Hermon %p could not allocate %d MTT entries\n",
646
mtt_base_addr = ( ( hermon->cap.reserved_mtts + mtt_offset ) *
647
hermon->cap.mtt_entry_size );
650
/* Fill in MTT structure */
651
mtt->mtt_offset = mtt_offset;
652
mtt->num_pages = num_pages;
653
mtt->mtt_base_addr = mtt_base_addr;
654
mtt->page_offset = page_offset;
656
/* Construct and issue WRITE_MTT commands */
657
for ( i = 0 ; i < num_pages ; i++ ) {
658
memset ( &write_mtt, 0, sizeof ( write_mtt ) );
659
MLX_FILL_1 ( &write_mtt.mtt_base_addr, 1,
660
value, mtt_base_addr );
661
MLX_FILL_H ( &write_mtt.mtt, 0, ptag_h, addr );
662
MLX_FILL_2 ( &write_mtt.mtt, 1,
664
ptag_l, ( addr >> 3 ) );
665
if ( ( rc = hermon_cmd_write_mtt ( hermon,
666
&write_mtt ) ) != 0 ) {
667
DBGC ( hermon, "Hermon %p could not write MTT at %x\n",
668
hermon, mtt_base_addr );
671
addr += HERMON_PAGE_SIZE;
672
mtt_base_addr += hermon->cap.mtt_entry_size;
675
DBGC ( hermon, "Hermon %p MTT entries [%#x,%#x] for "
676
"[%08lx,%08lx,%08lx,%08lx)\n", hermon, mtt->mtt_offset,
677
( mtt->mtt_offset + mtt->num_pages - 1 ), start,
678
( start + page_offset ), ( start + len ), addr );
683
hermon_bitmask_free ( hermon->mtt_inuse, mtt_offset, num_pages );
691
* @v hermon Hermon device
692
* @v mtt MTT descriptor
694
static void hermon_free_mtt ( struct hermon *hermon,
695
struct hermon_mtt *mtt ) {
697
DBGC ( hermon, "Hermon %p MTT entries [%#x,%#x] freed\n",
698
hermon, mtt->mtt_offset,
699
( mtt->mtt_offset + mtt->num_pages - 1 ) );
700
hermon_bitmask_free ( hermon->mtt_inuse, mtt->mtt_offset,
704
/***************************************************************************
706
* Static configuration operations
708
***************************************************************************
712
* Calculate offset within static configuration
717
#define HERMON_MOD_STAT_CFG_OFFSET( field ) \
718
( ( MLX_BIT_OFFSET ( struct hermonprm_mod_stat_cfg_st, field ) / 8 ) \
719
& ~( sizeof ( struct hermonprm_scalar_parameter ) - 1 ) )
722
* Query or modify static configuration
724
* @v hermon Hermon device
726
* @v mode Command mode
727
* @v offset Offset within static configuration
728
* @v stat_cfg Static configuration
729
* @ret rc Return status code
731
static int hermon_mod_stat_cfg ( struct hermon *hermon, unsigned int port,
732
unsigned int mode, unsigned int offset,
733
struct hermonprm_mod_stat_cfg *stat_cfg ) {
734
struct hermonprm_scalar_parameter *portion =
735
( ( void * ) &stat_cfg->u.bytes[offset] );
736
struct hermonprm_mod_stat_cfg_input_mod mod;
740
assert ( ( offset % sizeof ( *portion ) ) == 0 );
742
/* Construct input modifier */
743
memset ( &mod, 0, sizeof ( mod ) );
744
MLX_FILL_2 ( &mod, 0,
749
if ( ( rc = hermon_cmd_mod_stat_cfg ( hermon, mode,
750
be32_to_cpu ( mod.u.dwords[0] ),
757
/***************************************************************************
761
***************************************************************************
765
* Issue management datagram
767
* @v ibdev Infiniband device
768
* @v mad Management datagram
769
* @ret rc Return status code
771
static int hermon_mad ( struct ib_device *ibdev, union ib_mad *mad ) {
772
struct hermon *hermon = ib_get_drvdata ( ibdev );
773
union hermonprm_mad mad_ifc;
776
linker_assert ( sizeof ( *mad ) == sizeof ( mad_ifc.mad ),
779
/* Copy in request packet */
780
memcpy ( &mad_ifc.mad, mad, sizeof ( mad_ifc.mad ) );
783
if ( ( rc = hermon_cmd_mad_ifc ( hermon, ibdev->port,
784
&mad_ifc ) ) != 0 ) {
785
DBGC ( hermon, "Hermon %p port %d could not issue MAD IFC: "
786
"%s\n", hermon, ibdev->port, strerror ( rc ) );
790
/* Copy out reply packet */
791
memcpy ( mad, &mad_ifc.mad, sizeof ( *mad ) );
793
if ( mad->hdr.status != 0 ) {
794
DBGC ( hermon, "Hermon %p port %d MAD IFC status %04x\n",
795
hermon, ibdev->port, ntohs ( mad->hdr.status ) );
801
/***************************************************************************
803
* Completion queue operations
805
***************************************************************************
809
* Dump completion queue context (for debugging only)
811
* @v hermon Hermon device
812
* @v cq Completion queue
813
* @ret rc Return status code
815
static __attribute__ (( unused )) int
816
hermon_dump_cqctx ( struct hermon *hermon, struct ib_completion_queue *cq ) {
817
struct hermonprm_completion_queue_context cqctx;
820
memset ( &cqctx, 0, sizeof ( cqctx ) );
821
if ( ( rc = hermon_cmd_query_cq ( hermon, cq->cqn, &cqctx ) ) != 0 ) {
822
DBGC ( hermon, "Hermon %p CQN %#lx QUERY_CQ failed: %s\n",
823
hermon, cq->cqn, strerror ( rc ) );
826
DBGC ( hermon, "Hermon %p CQN %#lx context:\n", hermon, cq->cqn );
827
DBGC_HDA ( hermon, 0, &cqctx, sizeof ( cqctx ) );
833
* Create completion queue
835
* @v ibdev Infiniband device
836
* @v cq Completion queue
837
* @ret rc Return status code
839
static int hermon_create_cq ( struct ib_device *ibdev,
840
struct ib_completion_queue *cq ) {
841
struct hermon *hermon = ib_get_drvdata ( ibdev );
842
struct hermon_completion_queue *hermon_cq;
843
struct hermonprm_completion_queue_context cqctx;
848
/* Find a free completion queue number */
849
cqn_offset = hermon_bitmask_alloc ( hermon->cq_inuse,
851
if ( cqn_offset < 0 ) {
852
DBGC ( hermon, "Hermon %p out of completion queues\n",
857
cq->cqn = ( hermon->cap.reserved_cqs + cqn_offset );
859
/* Allocate control structures */
860
hermon_cq = zalloc ( sizeof ( *hermon_cq ) );
866
/* Allocate doorbell */
867
hermon_cq->doorbell = malloc_dma ( sizeof ( hermon_cq->doorbell[0] ),
868
sizeof ( hermon_cq->doorbell[0] ) );
869
if ( ! hermon_cq->doorbell ) {
873
memset ( hermon_cq->doorbell, 0, sizeof ( hermon_cq->doorbell[0] ) );
875
/* Allocate completion queue itself */
876
hermon_cq->cqe_size = ( cq->num_cqes * sizeof ( hermon_cq->cqe[0] ) );
877
hermon_cq->cqe = malloc_dma ( hermon_cq->cqe_size,
878
sizeof ( hermon_cq->cqe[0] ) );
879
if ( ! hermon_cq->cqe ) {
883
memset ( hermon_cq->cqe, 0, hermon_cq->cqe_size );
884
for ( i = 0 ; i < cq->num_cqes ; i++ ) {
885
MLX_FILL_1 ( &hermon_cq->cqe[i].normal, 7, owner, 1 );
889
/* Allocate MTT entries */
890
if ( ( rc = hermon_alloc_mtt ( hermon, hermon_cq->cqe,
892
&hermon_cq->mtt ) ) != 0 )
895
/* Hand queue over to hardware */
896
memset ( &cqctx, 0, sizeof ( cqctx ) );
897
MLX_FILL_1 ( &cqctx, 0, st, 0xa /* "Event fired" */ );
898
MLX_FILL_1 ( &cqctx, 2,
899
page_offset, ( hermon_cq->mtt.page_offset >> 5 ) );
900
MLX_FILL_2 ( &cqctx, 3,
901
usr_page, HERMON_UAR_NON_EQ_PAGE,
902
log_cq_size, fls ( cq->num_cqes - 1 ) );
903
MLX_FILL_1 ( &cqctx, 5, c_eqn, hermon->eq.eqn );
904
MLX_FILL_H ( &cqctx, 6, mtt_base_addr_h,
905
hermon_cq->mtt.mtt_base_addr );
906
MLX_FILL_1 ( &cqctx, 7, mtt_base_addr_l,
907
( hermon_cq->mtt.mtt_base_addr >> 3 ) );
908
MLX_FILL_H ( &cqctx, 14, db_record_addr_h,
909
virt_to_phys ( hermon_cq->doorbell ) );
910
MLX_FILL_1 ( &cqctx, 15, db_record_addr_l,
911
( virt_to_phys ( hermon_cq->doorbell ) >> 3 ) );
912
if ( ( rc = hermon_cmd_sw2hw_cq ( hermon, cq->cqn, &cqctx ) ) != 0 ) {
913
DBGC ( hermon, "Hermon %p CQN %#lx SW2HW_CQ failed: %s\n",
914
hermon, cq->cqn, strerror ( rc ) );
918
DBGC ( hermon, "Hermon %p CQN %#lx ring [%08lx,%08lx), doorbell "
919
"%08lx\n", hermon, cq->cqn, virt_to_phys ( hermon_cq->cqe ),
920
( virt_to_phys ( hermon_cq->cqe ) + hermon_cq->cqe_size ),
921
virt_to_phys ( hermon_cq->doorbell ) );
922
ib_cq_set_drvdata ( cq, hermon_cq );
926
hermon_free_mtt ( hermon, &hermon_cq->mtt );
928
free_dma ( hermon_cq->cqe, hermon_cq->cqe_size );
930
free_dma ( hermon_cq->doorbell, sizeof ( hermon_cq->doorbell[0] ) );
934
hermon_bitmask_free ( hermon->cq_inuse, cqn_offset, 1 );
940
* Destroy completion queue
942
* @v ibdev Infiniband device
943
* @v cq Completion queue
945
static void hermon_destroy_cq ( struct ib_device *ibdev,
946
struct ib_completion_queue *cq ) {
947
struct hermon *hermon = ib_get_drvdata ( ibdev );
948
struct hermon_completion_queue *hermon_cq = ib_cq_get_drvdata ( cq );
949
struct hermonprm_completion_queue_context cqctx;
953
/* Take ownership back from hardware */
954
if ( ( rc = hermon_cmd_hw2sw_cq ( hermon, cq->cqn, &cqctx ) ) != 0 ) {
955
DBGC ( hermon, "Hermon %p CQN %#lx FATAL HW2SW_CQ failed: "
956
"%s\n", hermon, cq->cqn, strerror ( rc ) );
957
/* Leak memory and return; at least we avoid corruption */
961
/* Free MTT entries */
962
hermon_free_mtt ( hermon, &hermon_cq->mtt );
965
free_dma ( hermon_cq->cqe, hermon_cq->cqe_size );
966
free_dma ( hermon_cq->doorbell, sizeof ( hermon_cq->doorbell[0] ) );
969
/* Mark queue number as free */
970
cqn_offset = ( cq->cqn - hermon->cap.reserved_cqs );
971
hermon_bitmask_free ( hermon->cq_inuse, cqn_offset, 1 );
973
ib_cq_set_drvdata ( cq, NULL );
976
/***************************************************************************
978
* Queue pair operations
980
***************************************************************************
984
* Assign queue pair number
986
* @v ibdev Infiniband device
988
* @ret rc Return status code
990
static int hermon_alloc_qpn ( struct ib_device *ibdev,
991
struct ib_queue_pair *qp ) {
992
struct hermon *hermon = ib_get_drvdata ( ibdev );
993
unsigned int port_offset;
996
/* Calculate queue pair number */
997
port_offset = ( ibdev->port - HERMON_PORT_BASE );
999
switch ( qp->type ) {
1001
qp->qpn = ( hermon->special_qpn_base + port_offset );
1004
qp->qpn = ( hermon->special_qpn_base + 2 + port_offset );
1009
/* Find a free queue pair number */
1010
qpn_offset = hermon_bitmask_alloc ( hermon->qp_inuse,
1011
HERMON_MAX_QPS, 1 );
1012
if ( qpn_offset < 0 ) {
1013
DBGC ( hermon, "Hermon %p out of queue pairs\n",
1017
qp->qpn = ( ( random() & HERMON_QPN_RANDOM_MASK ) |
1018
( hermon->qpn_base + qpn_offset ) );
1021
DBGC ( hermon, "Hermon %p unsupported QP type %d\n",
1028
* Free queue pair number
1030
* @v ibdev Infiniband device
1033
static void hermon_free_qpn ( struct ib_device *ibdev,
1034
struct ib_queue_pair *qp ) {
1035
struct hermon *hermon = ib_get_drvdata ( ibdev );
1038
qpn_offset = ( ( qp->qpn & ~HERMON_QPN_RANDOM_MASK )
1039
- hermon->qpn_base );
1040
if ( qpn_offset >= 0 )
1041
hermon_bitmask_free ( hermon->qp_inuse, qpn_offset, 1 );
1045
* Calculate transmission rate
1047
* @v av Address vector
1048
* @ret hermon_rate Hermon rate
1050
static unsigned int hermon_rate ( struct ib_address_vector *av ) {
1051
return ( ( ( av->rate >= IB_RATE_2_5 ) && ( av->rate <= IB_RATE_120 ) )
1052
? ( av->rate + 5 ) : 0 );
1056
* Calculate schedule queue
1058
* @v ibdev Infiniband device
1060
* @ret sched_queue Schedule queue
1062
static unsigned int hermon_sched_queue ( struct ib_device *ibdev,
1063
struct ib_queue_pair *qp ) {
1064
return ( ( ( qp->type == IB_QPT_SMI ) ?
1065
HERMON_SCHED_QP0 : HERMON_SCHED_DEFAULT ) |
1066
( ( ibdev->port - 1 ) << 6 ) );
1069
/** Queue pair transport service type map */
1070
static uint8_t hermon_qp_st[] = {
1071
[IB_QPT_SMI] = HERMON_ST_MLX,
1072
[IB_QPT_GSI] = HERMON_ST_MLX,
1073
[IB_QPT_UD] = HERMON_ST_UD,
1074
[IB_QPT_RC] = HERMON_ST_RC,
1075
[IB_QPT_ETH] = HERMON_ST_MLX,
1079
* Dump queue pair context (for debugging only)
1081
* @v hermon Hermon device
1083
* @ret rc Return status code
1085
static __attribute__ (( unused )) int
1086
hermon_dump_qpctx ( struct hermon *hermon, struct ib_queue_pair *qp ) {
1087
struct hermonprm_qp_ee_state_transitions qpctx;
1090
memset ( &qpctx, 0, sizeof ( qpctx ) );
1091
if ( ( rc = hermon_cmd_query_qp ( hermon, qp->qpn, &qpctx ) ) != 0 ) {
1092
DBGC ( hermon, "Hermon %p QPN %#lx QUERY_QP failed: %s\n",
1093
hermon, qp->qpn, strerror ( rc ) );
1096
DBGC ( hermon, "Hermon %p QPN %#lx context:\n", hermon, qp->qpn );
1097
DBGC_HDA ( hermon, 0, &qpctx.u.dwords[2], ( sizeof ( qpctx ) - 8 ) );
1105
* @v ibdev Infiniband device
1107
* @ret rc Return status code
1109
static int hermon_create_qp ( struct ib_device *ibdev,
1110
struct ib_queue_pair *qp ) {
1111
struct hermon *hermon = ib_get_drvdata ( ibdev );
1112
struct hermon_queue_pair *hermon_qp;
1113
struct hermonprm_qp_ee_state_transitions qpctx;
1114
struct hermonprm_wqe_segment_data_ptr *data;
1118
/* Calculate queue pair number */
1119
if ( ( rc = hermon_alloc_qpn ( ibdev, qp ) ) != 0 )
1122
/* Allocate control structures */
1123
hermon_qp = zalloc ( sizeof ( *hermon_qp ) );
1124
if ( ! hermon_qp ) {
1129
/* Allocate doorbells */
1130
hermon_qp->recv.doorbell =
1131
malloc_dma ( sizeof ( hermon_qp->recv.doorbell[0] ),
1132
sizeof ( hermon_qp->recv.doorbell[0] ) );
1133
if ( ! hermon_qp->recv.doorbell ) {
1135
goto err_recv_doorbell;
1137
memset ( hermon_qp->recv.doorbell, 0,
1138
sizeof ( hermon_qp->recv.doorbell[0] ) );
1139
hermon_qp->send.doorbell =
1140
( hermon->uar + HERMON_UAR_NON_EQ_PAGE * HERMON_PAGE_SIZE +
1141
HERMON_DB_POST_SND_OFFSET );
1143
/* Allocate work queue buffer */
1144
hermon_qp->send.num_wqes = ( qp->send.num_wqes /* headroom */ + 1 +
1145
( 2048 / sizeof ( hermon_qp->send.wqe[0] ) ) );
1146
hermon_qp->send.num_wqes =
1147
( 1 << fls ( hermon_qp->send.num_wqes - 1 ) ); /* round up */
1148
hermon_qp->send.wqe_size = ( hermon_qp->send.num_wqes *
1149
sizeof ( hermon_qp->send.wqe[0] ) );
1150
hermon_qp->recv.wqe_size = ( qp->recv.num_wqes *
1151
sizeof ( hermon_qp->recv.wqe[0] ) );
1152
if ( ( qp->type == IB_QPT_SMI ) || ( qp->type == IB_QPT_GSI ) ||
1153
( qp->type == IB_QPT_UD ) ) {
1154
hermon_qp->recv.grh_size = ( qp->recv.num_wqes *
1155
sizeof ( hermon_qp->recv.grh[0] ));
1157
hermon_qp->wqe_size = ( hermon_qp->send.wqe_size +
1158
hermon_qp->recv.wqe_size +
1159
hermon_qp->recv.grh_size );
1160
hermon_qp->wqe = malloc_dma ( hermon_qp->wqe_size,
1161
sizeof ( hermon_qp->send.wqe[0] ) );
1162
if ( ! hermon_qp->wqe ) {
1166
hermon_qp->send.wqe = hermon_qp->wqe;
1167
hermon_qp->recv.wqe = ( hermon_qp->wqe + hermon_qp->send.wqe_size );
1168
if ( hermon_qp->recv.grh_size ) {
1169
hermon_qp->recv.grh = ( hermon_qp->wqe +
1170
hermon_qp->send.wqe_size +
1171
hermon_qp->recv.wqe_size );
1174
/* Initialise work queue entries */
1175
memset ( hermon_qp->send.wqe, 0xff, hermon_qp->send.wqe_size );
1176
memset ( hermon_qp->recv.wqe, 0, hermon_qp->recv.wqe_size );
1177
data = &hermon_qp->recv.wqe[0].recv.data[0];
1178
for ( i = 0 ; i < ( hermon_qp->recv.wqe_size / sizeof ( *data ) ); i++){
1179
MLX_FILL_1 ( data, 1, l_key, HERMON_INVALID_LKEY );
1183
/* Allocate MTT entries */
1184
if ( ( rc = hermon_alloc_mtt ( hermon, hermon_qp->wqe,
1185
hermon_qp->wqe_size,
1186
&hermon_qp->mtt ) ) != 0 ) {
1190
/* Transition queue to INIT state */
1191
memset ( &qpctx, 0, sizeof ( qpctx ) );
1192
MLX_FILL_2 ( &qpctx, 2,
1193
qpc_eec_data.pm_state, HERMON_PM_STATE_MIGRATED,
1194
qpc_eec_data.st, hermon_qp_st[qp->type] );
1195
MLX_FILL_1 ( &qpctx, 3, qpc_eec_data.pd, HERMON_GLOBAL_PD );
1196
MLX_FILL_4 ( &qpctx, 4,
1197
qpc_eec_data.log_rq_size, fls ( qp->recv.num_wqes - 1 ),
1198
qpc_eec_data.log_rq_stride,
1199
( fls ( sizeof ( hermon_qp->recv.wqe[0] ) - 1 ) - 4 ),
1200
qpc_eec_data.log_sq_size,
1201
fls ( hermon_qp->send.num_wqes - 1 ),
1202
qpc_eec_data.log_sq_stride,
1203
( fls ( sizeof ( hermon_qp->send.wqe[0] ) - 1 ) - 4 ) );
1204
MLX_FILL_1 ( &qpctx, 5,
1205
qpc_eec_data.usr_page, HERMON_UAR_NON_EQ_PAGE );
1206
MLX_FILL_1 ( &qpctx, 33, qpc_eec_data.cqn_snd, qp->send.cq->cqn );
1207
MLX_FILL_4 ( &qpctx, 38,
1208
qpc_eec_data.rre, 1,
1209
qpc_eec_data.rwe, 1,
1210
qpc_eec_data.rae, 1,
1211
qpc_eec_data.page_offset,
1212
( hermon_qp->mtt.page_offset >> 6 ) );
1213
MLX_FILL_1 ( &qpctx, 41, qpc_eec_data.cqn_rcv, qp->recv.cq->cqn );
1214
MLX_FILL_H ( &qpctx, 42, qpc_eec_data.db_record_addr_h,
1215
virt_to_phys ( hermon_qp->recv.doorbell ) );
1216
MLX_FILL_1 ( &qpctx, 43, qpc_eec_data.db_record_addr_l,
1217
( virt_to_phys ( hermon_qp->recv.doorbell ) >> 2 ) );
1218
MLX_FILL_H ( &qpctx, 52, qpc_eec_data.mtt_base_addr_h,
1219
hermon_qp->mtt.mtt_base_addr );
1220
MLX_FILL_1 ( &qpctx, 53, qpc_eec_data.mtt_base_addr_l,
1221
( hermon_qp->mtt.mtt_base_addr >> 3 ) );
1222
if ( ( rc = hermon_cmd_rst2init_qp ( hermon, qp->qpn,
1224
DBGC ( hermon, "Hermon %p QPN %#lx RST2INIT_QP failed: %s\n",
1225
hermon, qp->qpn, strerror ( rc ) );
1226
goto err_rst2init_qp;
1228
hermon_qp->state = HERMON_QP_ST_INIT;
1230
DBGC ( hermon, "Hermon %p QPN %#lx send ring [%08lx,%08lx), doorbell "
1231
"%08lx\n", hermon, qp->qpn,
1232
virt_to_phys ( hermon_qp->send.wqe ),
1233
( virt_to_phys ( hermon_qp->send.wqe ) +
1234
hermon_qp->send.wqe_size ),
1235
virt_to_phys ( hermon_qp->send.doorbell ) );
1236
DBGC ( hermon, "Hermon %p QPN %#lx receive ring [%08lx,%08lx), "
1237
"doorbell %08lx\n", hermon, qp->qpn,
1238
virt_to_phys ( hermon_qp->recv.wqe ),
1239
( virt_to_phys ( hermon_qp->recv.wqe ) +
1240
hermon_qp->recv.wqe_size ),
1241
virt_to_phys ( hermon_qp->recv.doorbell ) );
1242
DBGC ( hermon, "Hermon %p QPN %#lx send CQN %#lx receive CQN %#lx\n",
1243
hermon, qp->qpn, qp->send.cq->cqn, qp->recv.cq->cqn );
1244
ib_qp_set_drvdata ( qp, hermon_qp );
1247
hermon_cmd_2rst_qp ( hermon, qp->qpn );
1249
hermon_free_mtt ( hermon, &hermon_qp->mtt );
1251
free_dma ( hermon_qp->wqe, hermon_qp->wqe_size );
1253
free_dma ( hermon_qp->recv.doorbell,
1254
sizeof ( hermon_qp->recv.doorbell[0] ) );
1258
hermon_free_qpn ( ibdev, qp );
1266
* @v ibdev Infiniband device
1268
* @ret rc Return status code
1270
static int hermon_modify_qp ( struct ib_device *ibdev,
1271
struct ib_queue_pair *qp ) {
1272
struct hermon *hermon = ib_get_drvdata ( ibdev );
1273
struct hermon_queue_pair *hermon_qp = ib_qp_get_drvdata ( qp );
1274
struct hermonprm_qp_ee_state_transitions qpctx;
1277
/* Transition queue to RTR state, if applicable */
1278
if ( hermon_qp->state < HERMON_QP_ST_RTR ) {
1279
memset ( &qpctx, 0, sizeof ( qpctx ) );
1280
MLX_FILL_2 ( &qpctx, 4,
1282
( ( qp->type == IB_QPT_ETH ) ?
1283
HERMON_MTU_ETH : HERMON_MTU_2048 ),
1284
qpc_eec_data.msg_max, 31 );
1285
MLX_FILL_1 ( &qpctx, 7,
1286
qpc_eec_data.remote_qpn_een, qp->av.qpn );
1287
MLX_FILL_1 ( &qpctx, 9,
1288
qpc_eec_data.primary_address_path.rlid,
1290
MLX_FILL_1 ( &qpctx, 10,
1291
qpc_eec_data.primary_address_path.max_stat_rate,
1292
hermon_rate ( &qp->av ) );
1293
memcpy ( &qpctx.u.dwords[12], &qp->av.gid,
1294
sizeof ( qp->av.gid ) );
1295
MLX_FILL_1 ( &qpctx, 16,
1296
qpc_eec_data.primary_address_path.sched_queue,
1297
hermon_sched_queue ( ibdev, qp ) );
1298
MLX_FILL_1 ( &qpctx, 39,
1299
qpc_eec_data.next_rcv_psn, qp->recv.psn );
1300
if ( ( rc = hermon_cmd_init2rtr_qp ( hermon, qp->qpn,
1302
DBGC ( hermon, "Hermon %p QPN %#lx INIT2RTR_QP failed:"
1303
" %s\n", hermon, qp->qpn, strerror ( rc ) );
1306
hermon_qp->state = HERMON_QP_ST_RTR;
1309
/* Transition queue to RTS state */
1310
if ( hermon_qp->state < HERMON_QP_ST_RTS ) {
1311
memset ( &qpctx, 0, sizeof ( qpctx ) );
1312
MLX_FILL_1 ( &qpctx, 10,
1313
qpc_eec_data.primary_address_path.ack_timeout,
1314
14 /* 4.096us * 2^(14) = 67ms */ );
1315
MLX_FILL_2 ( &qpctx, 30,
1316
qpc_eec_data.retry_count, HERMON_RETRY_MAX,
1317
qpc_eec_data.rnr_retry, HERMON_RETRY_MAX );
1318
MLX_FILL_1 ( &qpctx, 32,
1319
qpc_eec_data.next_send_psn, qp->send.psn );
1320
if ( ( rc = hermon_cmd_rtr2rts_qp ( hermon, qp->qpn,
1322
DBGC ( hermon, "Hermon %p QPN %#lx RTR2RTS_QP failed: "
1323
"%s\n", hermon, qp->qpn, strerror ( rc ) );
1326
hermon_qp->state = HERMON_QP_ST_RTS;
1329
/* Update parameters in RTS state */
1330
memset ( &qpctx, 0, sizeof ( qpctx ) );
1331
MLX_FILL_1 ( &qpctx, 0, opt_param_mask, HERMON_QP_OPT_PARAM_QKEY );
1332
MLX_FILL_1 ( &qpctx, 44, qpc_eec_data.q_key, qp->qkey );
1333
if ( ( rc = hermon_cmd_rts2rts_qp ( hermon, qp->qpn, &qpctx ) ) != 0 ){
1334
DBGC ( hermon, "Hermon %p QPN %#lx RTS2RTS_QP failed: %s\n",
1335
hermon, qp->qpn, strerror ( rc ) );
1343
* Destroy queue pair
1345
* @v ibdev Infiniband device
1348
static void hermon_destroy_qp ( struct ib_device *ibdev,
1349
struct ib_queue_pair *qp ) {
1350
struct hermon *hermon = ib_get_drvdata ( ibdev );
1351
struct hermon_queue_pair *hermon_qp = ib_qp_get_drvdata ( qp );
1354
/* Take ownership back from hardware */
1355
if ( ( rc = hermon_cmd_2rst_qp ( hermon, qp->qpn ) ) != 0 ) {
1356
DBGC ( hermon, "Hermon %p QPN %#lx FATAL 2RST_QP failed: %s\n",
1357
hermon, qp->qpn, strerror ( rc ) );
1358
/* Leak memory and return; at least we avoid corruption */
1362
/* Free MTT entries */
1363
hermon_free_mtt ( hermon, &hermon_qp->mtt );
1366
free_dma ( hermon_qp->wqe, hermon_qp->wqe_size );
1367
free_dma ( hermon_qp->recv.doorbell,
1368
sizeof ( hermon_qp->recv.doorbell[0] ) );
1371
/* Mark queue number as free */
1372
hermon_free_qpn ( ibdev, qp );
1374
ib_qp_set_drvdata ( qp, NULL );
1377
/***************************************************************************
1379
* Work request operations
1381
***************************************************************************
1385
* Construct UD send work queue entry
1387
* @v ibdev Infiniband device
1389
* @v dest Destination address vector
1390
* @v iobuf I/O buffer
1391
* @v wqe Send work queue entry
1392
* @ret opcode Control opcode
1394
static __attribute__ (( unused )) unsigned int
1395
hermon_fill_nop_send_wqe ( struct ib_device *ibdev __unused,
1396
struct ib_queue_pair *qp __unused,
1397
struct ib_address_vector *dest __unused,
1398
struct io_buffer *iobuf __unused,
1399
union hermon_send_wqe *wqe ) {
1401
MLX_FILL_1 ( &wqe->ctrl, 1, ds, ( sizeof ( wqe->ctrl ) / 16 ) );
1402
MLX_FILL_1 ( &wqe->ctrl, 2, c, 0x03 /* generate completion */ );
1403
return HERMON_OPCODE_NOP;
1407
* Construct UD send work queue entry
1409
* @v ibdev Infiniband device
1411
* @v dest Destination address vector
1412
* @v iobuf I/O buffer
1413
* @v wqe Send work queue entry
1414
* @ret opcode Control opcode
1417
hermon_fill_ud_send_wqe ( struct ib_device *ibdev,
1418
struct ib_queue_pair *qp __unused,
1419
struct ib_address_vector *dest,
1420
struct io_buffer *iobuf,
1421
union hermon_send_wqe *wqe ) {
1422
struct hermon *hermon = ib_get_drvdata ( ibdev );
1424
MLX_FILL_1 ( &wqe->ud.ctrl, 1, ds,
1425
( ( offsetof ( typeof ( wqe->ud ), data[1] ) / 16 ) ) );
1426
MLX_FILL_1 ( &wqe->ud.ctrl, 2, c, 0x03 /* generate completion */ );
1427
MLX_FILL_2 ( &wqe->ud.ud, 0,
1428
ud_address_vector.pd, HERMON_GLOBAL_PD,
1429
ud_address_vector.port_number, ibdev->port );
1430
MLX_FILL_2 ( &wqe->ud.ud, 1,
1431
ud_address_vector.rlid, dest->lid,
1432
ud_address_vector.g, dest->gid_present );
1433
MLX_FILL_1 ( &wqe->ud.ud, 2,
1434
ud_address_vector.max_stat_rate, hermon_rate ( dest ) );
1435
MLX_FILL_1 ( &wqe->ud.ud, 3, ud_address_vector.sl, dest->sl );
1436
memcpy ( &wqe->ud.ud.u.dwords[4], &dest->gid, sizeof ( dest->gid ) );
1437
MLX_FILL_1 ( &wqe->ud.ud, 8, destination_qp, dest->qpn );
1438
MLX_FILL_1 ( &wqe->ud.ud, 9, q_key, dest->qkey );
1439
MLX_FILL_1 ( &wqe->ud.data[0], 0, byte_count, iob_len ( iobuf ) );
1440
MLX_FILL_1 ( &wqe->ud.data[0], 1, l_key, hermon->lkey );
1441
MLX_FILL_H ( &wqe->ud.data[0], 2,
1442
local_address_h, virt_to_bus ( iobuf->data ) );
1443
MLX_FILL_1 ( &wqe->ud.data[0], 3,
1444
local_address_l, virt_to_bus ( iobuf->data ) );
1445
return HERMON_OPCODE_SEND;
1449
* Construct MLX send work queue entry
1451
* @v ibdev Infiniband device
1453
* @v dest Destination address vector
1454
* @v iobuf I/O buffer
1455
* @v wqe Send work queue entry
1456
* @ret opcode Control opcode
1459
hermon_fill_mlx_send_wqe ( struct ib_device *ibdev,
1460
struct ib_queue_pair *qp,
1461
struct ib_address_vector *dest,
1462
struct io_buffer *iobuf,
1463
union hermon_send_wqe *wqe ) {
1464
struct hermon *hermon = ib_get_drvdata ( ibdev );
1465
struct io_buffer headers;
1467
/* Construct IB headers */
1468
iob_populate ( &headers, &wqe->mlx.headers, 0,
1469
sizeof ( wqe->mlx.headers ) );
1470
iob_reserve ( &headers, sizeof ( wqe->mlx.headers ) );
1471
ib_push ( ibdev, &headers, qp, iob_len ( iobuf ), dest );
1473
/* Fill work queue entry */
1474
MLX_FILL_1 ( &wqe->mlx.ctrl, 1, ds,
1475
( ( offsetof ( typeof ( wqe->mlx ), data[2] ) / 16 ) ) );
1476
MLX_FILL_5 ( &wqe->mlx.ctrl, 2,
1477
c, 0x03 /* generate completion */,
1478
icrc, 0 /* generate ICRC */,
1479
max_statrate, hermon_rate ( dest ),
1481
v15, ( ( qp->ext_qpn == IB_QPN_SMI ) ? 1 : 0 ) );
1482
MLX_FILL_1 ( &wqe->mlx.ctrl, 3, rlid, dest->lid );
1483
MLX_FILL_1 ( &wqe->mlx.data[0], 0,
1484
byte_count, iob_len ( &headers ) );
1485
MLX_FILL_1 ( &wqe->mlx.data[0], 1, l_key, hermon->lkey );
1486
MLX_FILL_H ( &wqe->mlx.data[0], 2,
1487
local_address_h, virt_to_bus ( headers.data ) );
1488
MLX_FILL_1 ( &wqe->mlx.data[0], 3,
1489
local_address_l, virt_to_bus ( headers.data ) );
1490
MLX_FILL_1 ( &wqe->mlx.data[1], 0,
1491
byte_count, ( iob_len ( iobuf ) + 4 /* ICRC */ ) );
1492
MLX_FILL_1 ( &wqe->mlx.data[1], 1, l_key, hermon->lkey );
1493
MLX_FILL_H ( &wqe->mlx.data[1], 2,
1494
local_address_h, virt_to_bus ( iobuf->data ) );
1495
MLX_FILL_1 ( &wqe->mlx.data[1], 3,
1496
local_address_l, virt_to_bus ( iobuf->data ) );
1497
return HERMON_OPCODE_SEND;
1501
* Construct RC send work queue entry
1503
* @v ibdev Infiniband device
1505
* @v dest Destination address vector
1506
* @v iobuf I/O buffer
1507
* @v wqe Send work queue entry
1508
* @ret opcode Control opcode
1511
hermon_fill_rc_send_wqe ( struct ib_device *ibdev,
1512
struct ib_queue_pair *qp __unused,
1513
struct ib_address_vector *dest __unused,
1514
struct io_buffer *iobuf,
1515
union hermon_send_wqe *wqe ) {
1516
struct hermon *hermon = ib_get_drvdata ( ibdev );
1518
MLX_FILL_1 ( &wqe->rc.ctrl, 1, ds,
1519
( ( offsetof ( typeof ( wqe->rc ), data[1] ) / 16 ) ) );
1520
MLX_FILL_1 ( &wqe->rc.ctrl, 2, c, 0x03 /* generate completion */ );
1521
MLX_FILL_1 ( &wqe->rc.data[0], 0, byte_count, iob_len ( iobuf ) );
1522
MLX_FILL_1 ( &wqe->rc.data[0], 1, l_key, hermon->lkey );
1523
MLX_FILL_H ( &wqe->rc.data[0], 2,
1524
local_address_h, virt_to_bus ( iobuf->data ) );
1525
MLX_FILL_1 ( &wqe->rc.data[0], 3,
1526
local_address_l, virt_to_bus ( iobuf->data ) );
1527
return HERMON_OPCODE_SEND;
1531
* Construct Ethernet send work queue entry
1533
* @v ibdev Infiniband device
1535
* @v dest Destination address vector
1536
* @v iobuf I/O buffer
1537
* @v wqe Send work queue entry
1538
* @ret opcode Control opcode
1541
hermon_fill_eth_send_wqe ( struct ib_device *ibdev,
1542
struct ib_queue_pair *qp __unused,
1543
struct ib_address_vector *dest __unused,
1544
struct io_buffer *iobuf,
1545
union hermon_send_wqe *wqe ) {
1546
struct hermon *hermon = ib_get_drvdata ( ibdev );
1548
/* Fill work queue entry */
1549
MLX_FILL_1 ( &wqe->eth.ctrl, 1, ds,
1550
( ( offsetof ( typeof ( wqe->mlx ), data[1] ) / 16 ) ) );
1551
MLX_FILL_2 ( &wqe->eth.ctrl, 2,
1552
c, 0x03 /* generate completion */,
1553
s, 1 /* inhibit ICRC */ );
1554
MLX_FILL_1 ( &wqe->eth.data[0], 0,
1555
byte_count, iob_len ( iobuf ) );
1556
MLX_FILL_1 ( &wqe->eth.data[0], 1, l_key, hermon->lkey );
1557
MLX_FILL_H ( &wqe->eth.data[0], 2,
1558
local_address_h, virt_to_bus ( iobuf->data ) );
1559
MLX_FILL_1 ( &wqe->eth.data[0], 3,
1560
local_address_l, virt_to_bus ( iobuf->data ) );
1561
return HERMON_OPCODE_SEND;
1564
/** Work queue entry constructors */
1566
( * hermon_fill_send_wqe[] ) ( struct ib_device *ibdev,
1567
struct ib_queue_pair *qp,
1568
struct ib_address_vector *dest,
1569
struct io_buffer *iobuf,
1570
union hermon_send_wqe *wqe ) = {
1571
[IB_QPT_SMI] = hermon_fill_mlx_send_wqe,
1572
[IB_QPT_GSI] = hermon_fill_mlx_send_wqe,
1573
[IB_QPT_UD] = hermon_fill_ud_send_wqe,
1574
[IB_QPT_RC] = hermon_fill_rc_send_wqe,
1575
[IB_QPT_ETH] = hermon_fill_eth_send_wqe,
1579
* Post send work queue entry
1581
* @v ibdev Infiniband device
1583
* @v dest Destination address vector
1584
* @v iobuf I/O buffer
1585
* @ret rc Return status code
1587
static int hermon_post_send ( struct ib_device *ibdev,
1588
struct ib_queue_pair *qp,
1589
struct ib_address_vector *dest,
1590
struct io_buffer *iobuf ) {
1591
struct hermon *hermon = ib_get_drvdata ( ibdev );
1592
struct hermon_queue_pair *hermon_qp = ib_qp_get_drvdata ( qp );
1593
struct ib_work_queue *wq = &qp->send;
1594
struct hermon_send_work_queue *hermon_send_wq = &hermon_qp->send;
1595
union hermon_send_wqe *wqe;
1596
union hermonprm_doorbell_register db_reg;
1597
unsigned long wqe_idx_mask;
1598
unsigned long wqe_idx;
1600
unsigned int opcode;
1602
/* Allocate work queue entry */
1603
wqe_idx = ( wq->next_idx & ( hermon_send_wq->num_wqes - 1 ) );
1604
owner = ( ( wq->next_idx & hermon_send_wq->num_wqes ) ? 1 : 0 );
1605
wqe_idx_mask = ( wq->num_wqes - 1 );
1606
if ( wq->iobufs[ wqe_idx & wqe_idx_mask ] ) {
1607
DBGC ( hermon, "Hermon %p QPN %#lx send queue full",
1611
wq->iobufs[ wqe_idx & wqe_idx_mask ] = iobuf;
1612
wqe = &hermon_send_wq->wqe[wqe_idx];
1614
/* Construct work queue entry */
1615
memset ( ( ( ( void * ) wqe ) + 4 /* avoid ctrl.owner */ ), 0,
1616
( sizeof ( *wqe ) - 4 ) );
1617
assert ( qp->type < ( sizeof ( hermon_fill_send_wqe ) /
1618
sizeof ( hermon_fill_send_wqe[0] ) ) );
1619
assert ( hermon_fill_send_wqe[qp->type] != NULL );
1620
opcode = hermon_fill_send_wqe[qp->type] ( ibdev, qp, dest, iobuf, wqe );
1622
MLX_FILL_2 ( &wqe->ctrl, 0,
1625
DBGCP ( hermon, "Hermon %p QPN %#lx posting send WQE %#lx:\n",
1626
hermon, qp->qpn, wqe_idx );
1627
DBGCP_HDA ( hermon, virt_to_phys ( wqe ), wqe, sizeof ( *wqe ) );
1629
/* Ring doorbell register */
1630
MLX_FILL_1 ( &db_reg.send, 0, qn, qp->qpn );
1632
writel ( db_reg.dword[0], hermon_send_wq->doorbell );
1634
/* Update work queue's index */
1641
* Post receive work queue entry
1643
* @v ibdev Infiniband device
1645
* @v iobuf I/O buffer
1646
* @ret rc Return status code
1648
static int hermon_post_recv ( struct ib_device *ibdev,
1649
struct ib_queue_pair *qp,
1650
struct io_buffer *iobuf ) {
1651
struct hermon *hermon = ib_get_drvdata ( ibdev );
1652
struct hermon_queue_pair *hermon_qp = ib_qp_get_drvdata ( qp );
1653
struct ib_work_queue *wq = &qp->recv;
1654
struct hermon_recv_work_queue *hermon_recv_wq = &hermon_qp->recv;
1655
struct hermonprm_recv_wqe *wqe;
1656
struct hermonprm_wqe_segment_data_ptr *data;
1657
struct ib_global_route_header *grh;
1658
unsigned int wqe_idx_mask;
1660
/* Allocate work queue entry */
1661
wqe_idx_mask = ( wq->num_wqes - 1 );
1662
if ( wq->iobufs[wq->next_idx & wqe_idx_mask] ) {
1663
DBGC ( hermon, "Hermon %p QPN %#lx receive queue full",
1667
wq->iobufs[wq->next_idx & wqe_idx_mask] = iobuf;
1668
wqe = &hermon_recv_wq->wqe[wq->next_idx & wqe_idx_mask].recv;
1670
/* Construct work queue entry */
1671
data = &wqe->data[0];
1672
if ( hermon_qp->recv.grh ) {
1673
grh = &hermon_qp->recv.grh[wq->next_idx & wqe_idx_mask];
1674
MLX_FILL_1 ( data, 0, byte_count, sizeof ( *grh ) );
1675
MLX_FILL_1 ( data, 1, l_key, hermon->lkey );
1676
MLX_FILL_H ( data, 2, local_address_h, virt_to_bus ( grh ) );
1677
MLX_FILL_1 ( data, 3, local_address_l, virt_to_bus ( grh ) );
1680
MLX_FILL_1 ( data, 0, byte_count, iob_tailroom ( iobuf ) );
1681
MLX_FILL_1 ( data, 1, l_key, hermon->lkey );
1682
MLX_FILL_H ( data, 2, local_address_h, virt_to_bus ( iobuf->data ) );
1683
MLX_FILL_1 ( data, 3, local_address_l, virt_to_bus ( iobuf->data ) );
1685
/* Update work queue's index */
1688
/* Update doorbell record */
1690
MLX_FILL_1 ( hermon_recv_wq->doorbell, 0, receive_wqe_counter,
1691
( wq->next_idx & 0xffff ) );
1699
* @v ibdev Infiniband device
1700
* @v cq Completion queue
1701
* @v cqe Hardware completion queue entry
1702
* @ret rc Return status code
1704
static int hermon_complete ( struct ib_device *ibdev,
1705
struct ib_completion_queue *cq,
1706
union hermonprm_completion_entry *cqe ) {
1707
struct hermon *hermon = ib_get_drvdata ( ibdev );
1708
struct hermon_queue_pair *hermon_qp;
1709
struct ib_work_queue *wq;
1710
struct ib_queue_pair *qp;
1711
struct io_buffer *iobuf;
1712
struct ib_address_vector recv_dest;
1713
struct ib_address_vector recv_source;
1714
struct ib_global_route_header *grh;
1715
struct ib_address_vector *source;
1716
unsigned int opcode;
1719
unsigned long wqe_idx;
1720
unsigned long wqe_idx_mask;
1724
/* Parse completion */
1725
qpn = MLX_GET ( &cqe->normal, qpn );
1726
is_send = MLX_GET ( &cqe->normal, s_r );
1727
opcode = MLX_GET ( &cqe->normal, opcode );
1728
if ( opcode >= HERMON_OPCODE_RECV_ERROR ) {
1729
/* "s" field is not valid for error opcodes */
1730
is_send = ( opcode == HERMON_OPCODE_SEND_ERROR );
1731
DBGC ( hermon, "Hermon %p CQN %#lx syndrome %x vendor %x\n",
1732
hermon, cq->cqn, MLX_GET ( &cqe->error, syndrome ),
1733
MLX_GET ( &cqe->error, vendor_error_syndrome ) );
1735
/* Don't return immediately; propagate error to completer */
1738
/* Identify work queue */
1739
wq = ib_find_wq ( cq, qpn, is_send );
1741
DBGC ( hermon, "Hermon %p CQN %#lx unknown %s QPN %#lx\n",
1742
hermon, cq->cqn, ( is_send ? "send" : "recv" ), qpn );
1746
hermon_qp = ib_qp_get_drvdata ( qp );
1748
/* Identify work queue entry */
1749
wqe_idx = MLX_GET ( &cqe->normal, wqe_counter );
1750
wqe_idx_mask = ( wq->num_wqes - 1 );
1751
DBGCP ( hermon, "Hermon %p CQN %#lx QPN %#lx %s WQE %#lx completed:\n",
1752
hermon, cq->cqn, qp->qpn, ( is_send ? "send" : "recv" ),
1754
DBGCP_HDA ( hermon, virt_to_phys ( cqe ), cqe, sizeof ( *cqe ) );
1756
/* Identify I/O buffer */
1757
iobuf = wq->iobufs[ wqe_idx & wqe_idx_mask ];
1759
DBGC ( hermon, "Hermon %p CQN %#lx QPN %#lx empty %s WQE "
1760
"%#lx\n", hermon, cq->cqn, qp->qpn,
1761
( is_send ? "send" : "recv" ), wqe_idx );
1764
wq->iobufs[ wqe_idx & wqe_idx_mask ] = NULL;
1767
/* Hand off to completion handler */
1768
ib_complete_send ( ibdev, qp, iobuf, rc );
1770
/* Set received length */
1771
len = MLX_GET ( &cqe->normal, byte_cnt );
1772
memset ( &recv_dest, 0, sizeof ( recv_dest ) );
1773
recv_dest.qpn = qpn;
1774
memset ( &recv_source, 0, sizeof ( recv_source ) );
1775
switch ( qp->type ) {
1779
/* Locate corresponding GRH */
1780
assert ( hermon_qp->recv.grh != NULL );
1781
grh = &hermon_qp->recv.grh[ wqe_idx & wqe_idx_mask ];
1782
len -= sizeof ( *grh );
1783
/* Construct address vector */
1784
source = &recv_source;
1785
source->qpn = MLX_GET ( &cqe->normal, srq_rqpn );
1786
source->lid = MLX_GET ( &cqe->normal, slid_smac47_32 );
1787
source->sl = MLX_GET ( &cqe->normal, sl );
1788
recv_dest.gid_present = source->gid_present =
1789
MLX_GET ( &cqe->normal, g );
1790
memcpy ( &recv_dest.gid, &grh->dgid,
1791
sizeof ( recv_dest.gid ) );
1792
memcpy ( &source->gid, &grh->sgid,
1793
sizeof ( source->gid ) );
1799
/* Construct address vector */
1800
source = &recv_source;
1801
source->vlan_present = MLX_GET ( &cqe->normal, vlan );
1802
source->vlan = MLX_GET ( &cqe->normal, vid );
1808
assert ( len <= iob_tailroom ( iobuf ) );
1809
iob_put ( iobuf, len );
1810
/* Hand off to completion handler */
1811
ib_complete_recv ( ibdev, qp, &recv_dest, source, iobuf, rc );
1818
* Poll completion queue
1820
* @v ibdev Infiniband device
1821
* @v cq Completion queue
1823
static void hermon_poll_cq ( struct ib_device *ibdev,
1824
struct ib_completion_queue *cq ) {
1825
struct hermon *hermon = ib_get_drvdata ( ibdev );
1826
struct hermon_completion_queue *hermon_cq = ib_cq_get_drvdata ( cq );
1827
union hermonprm_completion_entry *cqe;
1828
unsigned int cqe_idx_mask;
1832
/* Look for completion entry */
1833
cqe_idx_mask = ( cq->num_cqes - 1 );
1834
cqe = &hermon_cq->cqe[cq->next_idx & cqe_idx_mask];
1835
if ( MLX_GET ( &cqe->normal, owner ) ^
1836
( ( cq->next_idx & cq->num_cqes ) ? 1 : 0 ) ) {
1837
/* Entry still owned by hardware; end of poll */
1841
/* Handle completion */
1842
if ( ( rc = hermon_complete ( ibdev, cq, cqe ) ) != 0 ) {
1843
DBGC ( hermon, "Hermon %p CQN %#lx failed to complete:"
1844
" %s\n", hermon, cq->cqn, strerror ( rc ) );
1845
DBGC_HDA ( hermon, virt_to_phys ( cqe ),
1846
cqe, sizeof ( *cqe ) );
1849
/* Update completion queue's index */
1852
/* Update doorbell record */
1853
MLX_FILL_1 ( hermon_cq->doorbell, 0, update_ci,
1854
( cq->next_idx & 0x00ffffffUL ) );
1858
/***************************************************************************
1862
***************************************************************************
1866
* Create event queue
1868
* @v hermon Hermon device
1869
* @ret rc Return status code
1871
static int hermon_create_eq ( struct hermon *hermon ) {
1872
struct hermon_event_queue *hermon_eq = &hermon->eq;
1873
struct hermonprm_eqc eqctx;
1874
struct hermonprm_event_mask mask;
1878
/* Select event queue number */
1879
hermon_eq->eqn = ( 4 * hermon->cap.reserved_uars );
1880
if ( hermon_eq->eqn < hermon->cap.reserved_eqs )
1881
hermon_eq->eqn = hermon->cap.reserved_eqs;
1883
/* Calculate doorbell address */
1884
hermon_eq->doorbell =
1885
( hermon->uar + HERMON_DB_EQ_OFFSET ( hermon_eq->eqn ) );
1887
/* Allocate event queue itself */
1888
hermon_eq->eqe_size =
1889
( HERMON_NUM_EQES * sizeof ( hermon_eq->eqe[0] ) );
1890
hermon_eq->eqe = malloc_dma ( hermon_eq->eqe_size,
1891
sizeof ( hermon_eq->eqe[0] ) );
1892
if ( ! hermon_eq->eqe ) {
1896
memset ( hermon_eq->eqe, 0, hermon_eq->eqe_size );
1897
for ( i = 0 ; i < HERMON_NUM_EQES ; i++ ) {
1898
MLX_FILL_1 ( &hermon_eq->eqe[i].generic, 7, owner, 1 );
1902
/* Allocate MTT entries */
1903
if ( ( rc = hermon_alloc_mtt ( hermon, hermon_eq->eqe,
1904
hermon_eq->eqe_size,
1905
&hermon_eq->mtt ) ) != 0 )
1908
/* Hand queue over to hardware */
1909
memset ( &eqctx, 0, sizeof ( eqctx ) );
1910
MLX_FILL_2 ( &eqctx, 0,
1911
st, 0xa /* "Fired" */,
1913
MLX_FILL_1 ( &eqctx, 2,
1914
page_offset, ( hermon_eq->mtt.page_offset >> 5 ) );
1915
MLX_FILL_1 ( &eqctx, 3, log_eq_size, fls ( HERMON_NUM_EQES - 1 ) );
1916
MLX_FILL_H ( &eqctx, 6, mtt_base_addr_h,
1917
hermon_eq->mtt.mtt_base_addr );
1918
MLX_FILL_1 ( &eqctx, 7, mtt_base_addr_l,
1919
( hermon_eq->mtt.mtt_base_addr >> 3 ) );
1920
if ( ( rc = hermon_cmd_sw2hw_eq ( hermon, hermon_eq->eqn,
1922
DBGC ( hermon, "Hermon %p EQN %#lx SW2HW_EQ failed: %s\n",
1923
hermon, hermon_eq->eqn, strerror ( rc ) );
1927
/* Map all events to this event queue */
1928
memset ( &mask, 0xff, sizeof ( mask ) );
1929
if ( ( rc = hermon_cmd_map_eq ( hermon,
1930
( HERMON_MAP_EQ | hermon_eq->eqn ),
1932
DBGC ( hermon, "Hermon %p EQN %#lx MAP_EQ failed: %s\n",
1933
hermon, hermon_eq->eqn, strerror ( rc ) );
1937
DBGC ( hermon, "Hermon %p EQN %#lx ring [%08lx,%08lx), doorbell "
1938
"%08lx\n", hermon, hermon_eq->eqn,
1939
virt_to_phys ( hermon_eq->eqe ),
1940
( virt_to_phys ( hermon_eq->eqe ) + hermon_eq->eqe_size ),
1941
virt_to_phys ( hermon_eq->doorbell ) );
1945
hermon_cmd_hw2sw_eq ( hermon, hermon_eq->eqn, &eqctx );
1947
hermon_free_mtt ( hermon, &hermon_eq->mtt );
1949
free_dma ( hermon_eq->eqe, hermon_eq->eqe_size );
1951
memset ( hermon_eq, 0, sizeof ( *hermon_eq ) );
1956
* Destroy event queue
1958
* @v hermon Hermon device
1960
static void hermon_destroy_eq ( struct hermon *hermon ) {
1961
struct hermon_event_queue *hermon_eq = &hermon->eq;
1962
struct hermonprm_eqc eqctx;
1963
struct hermonprm_event_mask mask;
1966
/* Unmap events from event queue */
1967
memset ( &mask, 0xff, sizeof ( mask ) );
1968
if ( ( rc = hermon_cmd_map_eq ( hermon,
1969
( HERMON_UNMAP_EQ | hermon_eq->eqn ),
1971
DBGC ( hermon, "Hermon %p EQN %#lx FATAL MAP_EQ failed to "
1972
"unmap: %s\n", hermon, hermon_eq->eqn, strerror ( rc ) );
1973
/* Continue; HCA may die but system should survive */
1976
/* Take ownership back from hardware */
1977
if ( ( rc = hermon_cmd_hw2sw_eq ( hermon, hermon_eq->eqn,
1979
DBGC ( hermon, "Hermon %p EQN %#lx FATAL HW2SW_EQ failed: %s\n",
1980
hermon, hermon_eq->eqn, strerror ( rc ) );
1981
/* Leak memory and return; at least we avoid corruption */
1985
/* Free MTT entries */
1986
hermon_free_mtt ( hermon, &hermon_eq->mtt );
1989
free_dma ( hermon_eq->eqe, hermon_eq->eqe_size );
1990
memset ( hermon_eq, 0, sizeof ( *hermon_eq ) );
1994
* Handle port state event
1996
* @v hermon Hermon device
1997
* @v eqe Port state change event queue entry
1999
static void hermon_event_port_state_change ( struct hermon *hermon,
2000
union hermonprm_event_entry *eqe){
2004
/* Get port and link status */
2005
port = ( MLX_GET ( &eqe->port_state_change, data.p ) - 1 );
2006
link_up = ( MLX_GET ( &eqe->generic, event_sub_type ) & 0x04 );
2007
DBGC ( hermon, "Hermon %p port %d link %s\n", hermon, ( port + 1 ),
2008
( link_up ? "up" : "down" ) );
2011
if ( port >= hermon->cap.num_ports ) {
2012
DBGC ( hermon, "Hermon %p port %d does not exist!\n",
2013
hermon, ( port + 1 ) );
2017
/* Notify device of port state change */
2018
hermon->port[port].type->state_change ( hermon, &hermon->port[port],
2025
* @v ibdev Infiniband device
2027
static void hermon_poll_eq ( struct ib_device *ibdev ) {
2028
struct hermon *hermon = ib_get_drvdata ( ibdev );
2029
struct hermon_event_queue *hermon_eq = &hermon->eq;
2030
union hermonprm_event_entry *eqe;
2031
union hermonprm_doorbell_register db_reg;
2032
unsigned int eqe_idx_mask;
2033
unsigned int event_type;
2035
/* No event is generated upon reaching INIT, so we must poll
2036
* separately for link state changes while we remain DOWN.
2038
if ( ib_is_open ( ibdev ) &&
2039
( ibdev->port_state == IB_PORT_STATE_DOWN ) ) {
2040
ib_smc_update ( ibdev, hermon_mad );
2043
/* Poll event queue */
2045
/* Look for event entry */
2046
eqe_idx_mask = ( HERMON_NUM_EQES - 1 );
2047
eqe = &hermon_eq->eqe[hermon_eq->next_idx & eqe_idx_mask];
2048
if ( MLX_GET ( &eqe->generic, owner ) ^
2049
( ( hermon_eq->next_idx & HERMON_NUM_EQES ) ? 1 : 0 ) ) {
2050
/* Entry still owned by hardware; end of poll */
2053
DBGCP ( hermon, "Hermon %p EQN %#lx event:\n",
2054
hermon, hermon_eq->eqn );
2055
DBGCP_HDA ( hermon, virt_to_phys ( eqe ),
2056
eqe, sizeof ( *eqe ) );
2059
event_type = MLX_GET ( &eqe->generic, event_type );
2060
switch ( event_type ) {
2061
case HERMON_EV_PORT_STATE_CHANGE:
2062
hermon_event_port_state_change ( hermon, eqe );
2065
DBGC ( hermon, "Hermon %p EQN %#lx unrecognised event "
2067
hermon, hermon_eq->eqn, event_type );
2068
DBGC_HDA ( hermon, virt_to_phys ( eqe ),
2069
eqe, sizeof ( *eqe ) );
2073
/* Update event queue's index */
2074
hermon_eq->next_idx++;
2077
MLX_FILL_1 ( &db_reg.event, 0,
2078
ci, ( hermon_eq->next_idx & 0x00ffffffUL ) );
2079
writel ( db_reg.dword[0], hermon_eq->doorbell );
2083
/***************************************************************************
2087
***************************************************************************
2091
* Map virtual to physical address for firmware usage
2093
* @v hermon Hermon device
2094
* @v map Mapping function
2095
* @v va Virtual address
2096
* @v pa Physical address
2097
* @v len Length of region
2098
* @ret rc Return status code
2100
static int hermon_map_vpm ( struct hermon *hermon,
2101
int ( *map ) ( struct hermon *hermon,
2102
const struct hermonprm_virtual_physical_mapping* ),
2103
uint64_t va, physaddr_t pa, size_t len ) {
2104
struct hermonprm_virtual_physical_mapping mapping;
2113
assert ( ( va & ( HERMON_PAGE_SIZE - 1 ) ) == 0 );
2114
assert ( ( pa & ( HERMON_PAGE_SIZE - 1 ) ) == 0 );
2115
assert ( ( len & ( HERMON_PAGE_SIZE - 1 ) ) == 0 );
2117
/* Calculate starting points */
2119
end = ( start + len );
2120
size = ( 1UL << ( fls ( start ^ end ) - 1 ) );
2121
low = high = ( end & ~( size - 1 ) );
2122
assert ( start < low );
2123
assert ( high <= end );
2125
/* These mappings tend to generate huge volumes of
2126
* uninteresting debug data, which basically makes it
2127
* impossible to use debugging otherwise.
2129
DBG_DISABLE ( DBGLVL_LOG | DBGLVL_EXTRA );
2131
/* Map blocks in descending order of size */
2132
while ( size >= HERMON_PAGE_SIZE ) {
2134
/* Find the next candidate block */
2135
if ( ( low - size ) >= start ) {
2138
} else if ( ( high + size ) <= end ) {
2145
assert ( ( va & ( size - 1 ) ) == 0 );
2146
assert ( ( pa & ( size - 1 ) ) == 0 );
2148
/* Map this block */
2149
memset ( &mapping, 0, sizeof ( mapping ) );
2150
MLX_FILL_1 ( &mapping, 0, va_h, ( va >> 32 ) );
2151
MLX_FILL_1 ( &mapping, 1, va_l, ( va >> 12 ) );
2152
MLX_FILL_H ( &mapping, 2, pa_h, pa );
2153
MLX_FILL_2 ( &mapping, 3,
2154
log2size, ( ( fls ( size ) - 1 ) - 12 ),
2155
pa_l, ( pa >> 12 ) );
2156
if ( ( rc = map ( hermon, &mapping ) ) != 0 ) {
2157
DBG_ENABLE ( DBGLVL_LOG | DBGLVL_EXTRA );
2158
DBGC ( hermon, "Hermon %p could not map %08llx+%zx to "
2160
hermon, va, size, pa, strerror ( rc ) );
2165
assert ( low == start );
2166
assert ( high == end );
2168
DBG_ENABLE ( DBGLVL_LOG | DBGLVL_EXTRA );
2173
* Start firmware running
2175
* @v hermon Hermon device
2176
* @ret rc Return status code
2178
static int hermon_start_firmware ( struct hermon *hermon ) {
2179
struct hermonprm_query_fw fw;
2180
unsigned int fw_pages;
2185
/* Get firmware parameters */
2186
if ( ( rc = hermon_cmd_query_fw ( hermon, &fw ) ) != 0 ) {
2187
DBGC ( hermon, "Hermon %p could not query firmware: %s\n",
2188
hermon, strerror ( rc ) );
2191
DBGC ( hermon, "Hermon %p firmware version %d.%d.%d\n", hermon,
2192
MLX_GET ( &fw, fw_rev_major ), MLX_GET ( &fw, fw_rev_minor ),
2193
MLX_GET ( &fw, fw_rev_subminor ) );
2194
fw_pages = MLX_GET ( &fw, fw_pages );
2195
DBGC ( hermon, "Hermon %p requires %d pages (%d kB) for firmware\n",
2196
hermon, fw_pages, ( fw_pages * 4 ) );
2198
/* Allocate firmware pages and map firmware area */
2199
fw_len = ( fw_pages * HERMON_PAGE_SIZE );
2200
if ( ! hermon->firmware_area ) {
2201
hermon->firmware_len = fw_len;
2202
hermon->firmware_area = umalloc ( hermon->firmware_len );
2203
if ( ! hermon->firmware_area ) {
2208
assert ( hermon->firmware_len == fw_len );
2210
fw_base = user_to_phys ( hermon->firmware_area, 0 );
2211
DBGC ( hermon, "Hermon %p firmware area at physical [%08lx,%08lx)\n",
2212
hermon, fw_base, ( fw_base + fw_len ) );
2213
if ( ( rc = hermon_map_vpm ( hermon, hermon_cmd_map_fa,
2214
0, fw_base, fw_len ) ) != 0 ) {
2215
DBGC ( hermon, "Hermon %p could not map firmware: %s\n",
2216
hermon, strerror ( rc ) );
2220
/* Start firmware */
2221
if ( ( rc = hermon_cmd_run_fw ( hermon ) ) != 0 ) {
2222
DBGC ( hermon, "Hermon %p could not run firmware: %s\n",
2223
hermon, strerror ( rc ) );
2227
DBGC ( hermon, "Hermon %p firmware started\n", hermon );
2232
hermon_cmd_unmap_fa ( hermon );
2239
* Stop firmware running
2241
* @v hermon Hermon device
2243
static void hermon_stop_firmware ( struct hermon *hermon ) {
2246
if ( ( rc = hermon_cmd_unmap_fa ( hermon ) ) != 0 ) {
2247
DBGC ( hermon, "Hermon %p FATAL could not stop firmware: %s\n",
2248
hermon, strerror ( rc ) );
2249
/* Leak memory and return; at least we avoid corruption */
2250
hermon->firmware_area = UNULL;
2255
/***************************************************************************
2257
* Infinihost Context Memory management
2259
***************************************************************************
2265
* @v hermon Hermon device
2266
* @ret rc Return status code
2268
static int hermon_get_cap ( struct hermon *hermon ) {
2269
struct hermonprm_query_dev_cap dev_cap;
2272
if ( ( rc = hermon_cmd_query_dev_cap ( hermon, &dev_cap ) ) != 0 ) {
2273
DBGC ( hermon, "Hermon %p could not get device limits: %s\n",
2274
hermon, strerror ( rc ) );
2278
hermon->cap.cmpt_entry_size = MLX_GET ( &dev_cap, c_mpt_entry_sz );
2279
hermon->cap.reserved_qps =
2280
( 1 << MLX_GET ( &dev_cap, log2_rsvd_qps ) );
2281
hermon->cap.qpc_entry_size = MLX_GET ( &dev_cap, qpc_entry_sz );
2282
hermon->cap.altc_entry_size = MLX_GET ( &dev_cap, altc_entry_sz );
2283
hermon->cap.auxc_entry_size = MLX_GET ( &dev_cap, aux_entry_sz );
2284
hermon->cap.reserved_srqs =
2285
( 1 << MLX_GET ( &dev_cap, log2_rsvd_srqs ) );
2286
hermon->cap.srqc_entry_size = MLX_GET ( &dev_cap, srq_entry_sz );
2287
hermon->cap.reserved_cqs =
2288
( 1 << MLX_GET ( &dev_cap, log2_rsvd_cqs ) );
2289
hermon->cap.cqc_entry_size = MLX_GET ( &dev_cap, cqc_entry_sz );
2290
hermon->cap.reserved_eqs = MLX_GET ( &dev_cap, num_rsvd_eqs );
2291
if ( hermon->cap.reserved_eqs == 0 ) {
2292
/* Backward compatibility */
2293
hermon->cap.reserved_eqs =
2294
( 1 << MLX_GET ( &dev_cap, log2_rsvd_eqs ) );
2296
hermon->cap.eqc_entry_size = MLX_GET ( &dev_cap, eqc_entry_sz );
2297
hermon->cap.reserved_mtts =
2298
( 1 << MLX_GET ( &dev_cap, log2_rsvd_mtts ) );
2299
hermon->cap.mtt_entry_size = MLX_GET ( &dev_cap, mtt_entry_sz );
2300
hermon->cap.reserved_mrws =
2301
( 1 << MLX_GET ( &dev_cap, log2_rsvd_mrws ) );
2302
hermon->cap.dmpt_entry_size = MLX_GET ( &dev_cap, d_mpt_entry_sz );
2303
hermon->cap.reserved_uars = MLX_GET ( &dev_cap, num_rsvd_uars );
2304
hermon->cap.num_ports = MLX_GET ( &dev_cap, num_ports );
2305
hermon->cap.dpdp = MLX_GET ( &dev_cap, dpdp );
2308
if ( hermon->cap.num_ports > HERMON_MAX_PORTS ) {
2309
DBGC ( hermon, "Hermon %p has %d ports (only %d supported)\n",
2310
hermon, hermon->cap.num_ports, HERMON_MAX_PORTS );
2311
hermon->cap.num_ports = HERMON_MAX_PORTS;
2320
* @v icm_offset Current ICM offset
2321
* @v len ICM table length
2322
* @ret icm_offset ICM offset
2324
static uint64_t icm_align ( uint64_t icm_offset, size_t len ) {
2326
/* Round up to a multiple of the table size */
2327
assert ( len == ( 1UL << ( fls ( len ) - 1 ) ) );
2328
return ( ( icm_offset + len - 1 ) & ~( ( ( uint64_t ) len ) - 1 ) );
2332
* Map ICM (allocating if necessary)
2334
* @v hermon Hermon device
2335
* @v init_hca INIT_HCA structure to fill in
2336
* @ret rc Return status code
2338
static int hermon_map_icm ( struct hermon *hermon,
2339
struct hermonprm_init_hca *init_hca ) {
2340
struct hermonprm_scalar_parameter icm_size;
2341
struct hermonprm_scalar_parameter icm_aux_size;
2342
uint64_t icm_offset = 0;
2343
unsigned int log_num_qps, log_num_srqs, log_num_cqs, log_num_eqs;
2344
unsigned int log_num_mtts, log_num_mpts, log_num_mcs;
2345
size_t cmpt_max_len;
2346
size_t icm_len, icm_aux_len;
2348
physaddr_t icm_phys;
2353
* Start by carving up the ICM virtual address space
2357
/* Calculate number of each object type within ICM */
2358
log_num_qps = fls ( hermon->cap.reserved_qps +
2359
HERMON_RSVD_SPECIAL_QPS + HERMON_MAX_QPS - 1 );
2360
log_num_srqs = fls ( hermon->cap.reserved_srqs - 1 );
2361
log_num_cqs = fls ( hermon->cap.reserved_cqs + HERMON_MAX_CQS - 1 );
2362
log_num_eqs = fls ( hermon->cap.reserved_eqs + HERMON_MAX_EQS - 1 );
2363
log_num_mtts = fls ( hermon->cap.reserved_mtts + HERMON_MAX_MTTS - 1 );
2364
log_num_mpts = fls ( hermon->cap.reserved_mrws + 1 - 1 );
2365
log_num_mcs = HERMON_LOG_MULTICAST_HASH_SIZE;
2367
/* ICM starts with the cMPT tables, which are sparse */
2368
cmpt_max_len = ( HERMON_CMPT_MAX_ENTRIES *
2369
( ( uint64_t ) hermon->cap.cmpt_entry_size ) );
2370
len = ( ( ( ( 1 << log_num_qps ) * hermon->cap.cmpt_entry_size ) +
2371
HERMON_PAGE_SIZE - 1 ) & ~( HERMON_PAGE_SIZE - 1 ) );
2372
hermon->icm_map[HERMON_ICM_QP_CMPT].offset = icm_offset;
2373
hermon->icm_map[HERMON_ICM_QP_CMPT].len = len;
2374
icm_offset += cmpt_max_len;
2375
len = ( ( ( ( 1 << log_num_srqs ) * hermon->cap.cmpt_entry_size ) +
2376
HERMON_PAGE_SIZE - 1 ) & ~( HERMON_PAGE_SIZE - 1 ) );
2377
hermon->icm_map[HERMON_ICM_SRQ_CMPT].offset = icm_offset;
2378
hermon->icm_map[HERMON_ICM_SRQ_CMPT].len = len;
2379
icm_offset += cmpt_max_len;
2380
len = ( ( ( ( 1 << log_num_cqs ) * hermon->cap.cmpt_entry_size ) +
2381
HERMON_PAGE_SIZE - 1 ) & ~( HERMON_PAGE_SIZE - 1 ) );
2382
hermon->icm_map[HERMON_ICM_CQ_CMPT].offset = icm_offset;
2383
hermon->icm_map[HERMON_ICM_CQ_CMPT].len = len;
2384
icm_offset += cmpt_max_len;
2385
len = ( ( ( ( 1 << log_num_eqs ) * hermon->cap.cmpt_entry_size ) +
2386
HERMON_PAGE_SIZE - 1 ) & ~( HERMON_PAGE_SIZE - 1 ) );
2387
hermon->icm_map[HERMON_ICM_EQ_CMPT].offset = icm_offset;
2388
hermon->icm_map[HERMON_ICM_EQ_CMPT].len = len;
2389
icm_offset += cmpt_max_len;
2391
hermon->icm_map[HERMON_ICM_OTHER].offset = icm_offset;
2393
/* Queue pair contexts */
2394
len = ( ( 1 << log_num_qps ) * hermon->cap.qpc_entry_size );
2395
icm_offset = icm_align ( icm_offset, len );
2396
MLX_FILL_1 ( init_hca, 12,
2397
qpc_eec_cqc_eqc_rdb_parameters.qpc_base_addr_h,
2398
( icm_offset >> 32 ) );
2399
MLX_FILL_2 ( init_hca, 13,
2400
qpc_eec_cqc_eqc_rdb_parameters.qpc_base_addr_l,
2401
( icm_offset >> 5 ),
2402
qpc_eec_cqc_eqc_rdb_parameters.log_num_of_qp,
2404
DBGC ( hermon, "Hermon %p ICM QPC is %d x %#zx at [%08llx,%08llx)\n",
2405
hermon, ( 1 << log_num_qps ), hermon->cap.qpc_entry_size,
2406
icm_offset, ( icm_offset + len ) );
2409
/* Extended alternate path contexts */
2410
len = ( ( 1 << log_num_qps ) * hermon->cap.altc_entry_size );
2411
icm_offset = icm_align ( icm_offset, len );
2412
MLX_FILL_1 ( init_hca, 24,
2413
qpc_eec_cqc_eqc_rdb_parameters.altc_base_addr_h,
2414
( icm_offset >> 32 ) );
2415
MLX_FILL_1 ( init_hca, 25,
2416
qpc_eec_cqc_eqc_rdb_parameters.altc_base_addr_l,
2418
DBGC ( hermon, "Hermon %p ICM ALTC is %d x %#zx at [%08llx,%08llx)\n",
2419
hermon, ( 1 << log_num_qps ), hermon->cap.altc_entry_size,
2420
icm_offset, ( icm_offset + len ) );
2423
/* Extended auxiliary contexts */
2424
len = ( ( 1 << log_num_qps ) * hermon->cap.auxc_entry_size );
2425
icm_offset = icm_align ( icm_offset, len );
2426
MLX_FILL_1 ( init_hca, 28,
2427
qpc_eec_cqc_eqc_rdb_parameters.auxc_base_addr_h,
2428
( icm_offset >> 32 ) );
2429
MLX_FILL_1 ( init_hca, 29,
2430
qpc_eec_cqc_eqc_rdb_parameters.auxc_base_addr_l,
2432
DBGC ( hermon, "Hermon %p ICM AUXC is %d x %#zx at [%08llx,%08llx)\n",
2433
hermon, ( 1 << log_num_qps ), hermon->cap.auxc_entry_size,
2434
icm_offset, ( icm_offset + len ) );
2437
/* Shared receive queue contexts */
2438
len = ( ( 1 << log_num_srqs ) * hermon->cap.srqc_entry_size );
2439
icm_offset = icm_align ( icm_offset, len );
2440
MLX_FILL_1 ( init_hca, 18,
2441
qpc_eec_cqc_eqc_rdb_parameters.srqc_base_addr_h,
2442
( icm_offset >> 32 ) );
2443
MLX_FILL_2 ( init_hca, 19,
2444
qpc_eec_cqc_eqc_rdb_parameters.srqc_base_addr_l,
2445
( icm_offset >> 5 ),
2446
qpc_eec_cqc_eqc_rdb_parameters.log_num_of_srq,
2448
DBGC ( hermon, "Hermon %p ICM SRQC is %d x %#zx at [%08llx,%08llx)\n",
2449
hermon, ( 1 << log_num_srqs ), hermon->cap.srqc_entry_size,
2450
icm_offset, ( icm_offset + len ) );
2453
/* Completion queue contexts */
2454
len = ( ( 1 << log_num_cqs ) * hermon->cap.cqc_entry_size );
2455
icm_offset = icm_align ( icm_offset, len );
2456
MLX_FILL_1 ( init_hca, 20,
2457
qpc_eec_cqc_eqc_rdb_parameters.cqc_base_addr_h,
2458
( icm_offset >> 32 ) );
2459
MLX_FILL_2 ( init_hca, 21,
2460
qpc_eec_cqc_eqc_rdb_parameters.cqc_base_addr_l,
2461
( icm_offset >> 5 ),
2462
qpc_eec_cqc_eqc_rdb_parameters.log_num_of_cq,
2464
DBGC ( hermon, "Hermon %p ICM CQC is %d x %#zx at [%08llx,%08llx)\n",
2465
hermon, ( 1 << log_num_cqs ), hermon->cap.cqc_entry_size,
2466
icm_offset, ( icm_offset + len ) );
2469
/* Event queue contexts */
2470
len = ( ( 1 << log_num_eqs ) * hermon->cap.eqc_entry_size );
2471
icm_offset = icm_align ( icm_offset, len );
2472
MLX_FILL_1 ( init_hca, 32,
2473
qpc_eec_cqc_eqc_rdb_parameters.eqc_base_addr_h,
2474
( icm_offset >> 32 ) );
2475
MLX_FILL_2 ( init_hca, 33,
2476
qpc_eec_cqc_eqc_rdb_parameters.eqc_base_addr_l,
2477
( icm_offset >> 5 ),
2478
qpc_eec_cqc_eqc_rdb_parameters.log_num_of_eq,
2480
DBGC ( hermon, "Hermon %p ICM EQC is %d x %#zx at [%08llx,%08llx)\n",
2481
hermon, ( 1 << log_num_eqs ), hermon->cap.eqc_entry_size,
2482
icm_offset, ( icm_offset + len ) );
2485
/* Memory translation table */
2486
len = ( ( 1 << log_num_mtts ) * hermon->cap.mtt_entry_size );
2487
icm_offset = icm_align ( icm_offset, len );
2488
MLX_FILL_1 ( init_hca, 64,
2489
tpt_parameters.mtt_base_addr_h, ( icm_offset >> 32 ) );
2490
MLX_FILL_1 ( init_hca, 65,
2491
tpt_parameters.mtt_base_addr_l, icm_offset );
2492
DBGC ( hermon, "Hermon %p ICM MTT is %d x %#zx at [%08llx,%08llx)\n",
2493
hermon, ( 1 << log_num_mtts ), hermon->cap.mtt_entry_size,
2494
icm_offset, ( icm_offset + len ) );
2497
/* Memory protection table */
2498
len = ( ( 1 << log_num_mpts ) * hermon->cap.dmpt_entry_size );
2499
icm_offset = icm_align ( icm_offset, len );
2500
MLX_FILL_1 ( init_hca, 60,
2501
tpt_parameters.dmpt_base_adr_h, ( icm_offset >> 32 ) );
2502
MLX_FILL_1 ( init_hca, 61,
2503
tpt_parameters.dmpt_base_adr_l, icm_offset );
2504
MLX_FILL_1 ( init_hca, 62,
2505
tpt_parameters.log_dmpt_sz, log_num_mpts );
2506
DBGC ( hermon, "Hermon %p ICM DMPT is %d x %#zx at [%08llx,%08llx)\n",
2507
hermon, ( 1 << log_num_mpts ), hermon->cap.dmpt_entry_size,
2508
icm_offset, ( icm_offset + len ) );
2511
/* Multicast table */
2512
len = ( ( 1 << log_num_mcs ) * sizeof ( struct hermonprm_mcg_entry ) );
2513
icm_offset = icm_align ( icm_offset, len );
2514
MLX_FILL_1 ( init_hca, 48,
2515
multicast_parameters.mc_base_addr_h,
2516
( icm_offset >> 32 ) );
2517
MLX_FILL_1 ( init_hca, 49,
2518
multicast_parameters.mc_base_addr_l, icm_offset );
2519
MLX_FILL_1 ( init_hca, 52,
2520
multicast_parameters.log_mc_table_entry_sz,
2521
fls ( sizeof ( struct hermonprm_mcg_entry ) - 1 ) );
2522
MLX_FILL_1 ( init_hca, 53,
2523
multicast_parameters.log_mc_table_hash_sz, log_num_mcs );
2524
MLX_FILL_1 ( init_hca, 54,
2525
multicast_parameters.log_mc_table_sz, log_num_mcs );
2526
DBGC ( hermon, "Hermon %p ICM MC is %d x %#zx at [%08llx,%08llx)\n",
2527
hermon, ( 1 << log_num_mcs ),
2528
sizeof ( struct hermonprm_mcg_entry ),
2529
icm_offset, ( icm_offset + len ) );
2533
hermon->icm_map[HERMON_ICM_OTHER].len =
2534
( icm_offset - hermon->icm_map[HERMON_ICM_OTHER].offset );
2537
* Allocate and map physical memory for (portions of) ICM
2540
* ICM AUX area (aligned to its own size)
2545
/* Calculate physical memory required for ICM */
2547
for ( i = 0 ; i < HERMON_ICM_NUM_REGIONS ; i++ ) {
2548
icm_len += hermon->icm_map[i].len;
2551
/* Get ICM auxiliary area size */
2552
memset ( &icm_size, 0, sizeof ( icm_size ) );
2553
MLX_FILL_1 ( &icm_size, 0, value_hi, ( icm_offset >> 32 ) );
2554
MLX_FILL_1 ( &icm_size, 1, value, icm_offset );
2555
if ( ( rc = hermon_cmd_set_icm_size ( hermon, &icm_size,
2556
&icm_aux_size ) ) != 0 ) {
2557
DBGC ( hermon, "Hermon %p could not set ICM size: %s\n",
2558
hermon, strerror ( rc ) );
2559
goto err_set_icm_size;
2561
icm_aux_len = ( MLX_GET ( &icm_aux_size, value ) * HERMON_PAGE_SIZE );
2563
/* Allocate ICM data and auxiliary area */
2564
DBGC ( hermon, "Hermon %p requires %zd kB ICM and %zd kB AUX ICM\n",
2565
hermon, ( icm_len / 1024 ), ( icm_aux_len / 1024 ) );
2566
if ( ! hermon->icm ) {
2567
hermon->icm_len = icm_len;
2568
hermon->icm_aux_len = icm_aux_len;
2569
hermon->icm = umalloc ( hermon->icm_aux_len + hermon->icm_len );
2570
if ( ! hermon->icm ) {
2575
assert ( hermon->icm_len == icm_len );
2576
assert ( hermon->icm_aux_len == icm_aux_len );
2578
icm_phys = user_to_phys ( hermon->icm, 0 );
2580
/* Map ICM auxiliary area */
2581
DBGC ( hermon, "Hermon %p mapping ICM AUX => %08lx\n",
2583
if ( ( rc = hermon_map_vpm ( hermon, hermon_cmd_map_icm_aux,
2584
0, icm_phys, icm_aux_len ) ) != 0 ) {
2585
DBGC ( hermon, "Hermon %p could not map AUX ICM: %s\n",
2586
hermon, strerror ( rc ) );
2587
goto err_map_icm_aux;
2589
icm_phys += icm_aux_len;
2592
for ( i = 0 ; i < HERMON_ICM_NUM_REGIONS ; i++ ) {
2593
DBGC ( hermon, "Hermon %p mapping ICM %llx+%zx => %08lx\n",
2594
hermon, hermon->icm_map[i].offset,
2595
hermon->icm_map[i].len, icm_phys );
2596
if ( ( rc = hermon_map_vpm ( hermon, hermon_cmd_map_icm,
2597
hermon->icm_map[i].offset,
2599
hermon->icm_map[i].len ) ) != 0 ){
2600
DBGC ( hermon, "Hermon %p could not map ICM: %s\n",
2601
hermon, strerror ( rc ) );
2604
icm_phys += hermon->icm_map[i].len;
2610
assert ( i == 0 ); /* We don't handle partial failure at present */
2612
hermon_cmd_unmap_icm_aux ( hermon );
2621
* @v hermon Hermon device
2623
static void hermon_unmap_icm ( struct hermon *hermon ) {
2624
struct hermonprm_scalar_parameter unmap_icm;
2627
for ( i = ( HERMON_ICM_NUM_REGIONS - 1 ) ; i >= 0 ; i-- ) {
2628
memset ( &unmap_icm, 0, sizeof ( unmap_icm ) );
2629
MLX_FILL_1 ( &unmap_icm, 0, value_hi,
2630
( hermon->icm_map[i].offset >> 32 ) );
2631
MLX_FILL_1 ( &unmap_icm, 1, value,
2632
hermon->icm_map[i].offset );
2633
hermon_cmd_unmap_icm ( hermon,
2634
( 1 << fls ( ( hermon->icm_map[i].len /
2635
HERMON_PAGE_SIZE ) - 1)),
2638
hermon_cmd_unmap_icm_aux ( hermon );
2641
/***************************************************************************
2643
* Initialisation and teardown
2645
***************************************************************************
2651
* @v hermon Hermon device
2653
static void hermon_reset ( struct hermon *hermon ) {
2654
struct pci_device *pci = hermon->pci;
2655
struct pci_config_backup backup;
2656
static const uint8_t backup_exclude[] =
2657
PCI_CONFIG_BACKUP_EXCLUDE ( 0x58, 0x5c );
2659
/* Perform device reset and preserve PCI configuration */
2660
pci_backup ( pci, &backup, backup_exclude );
2661
writel ( HERMON_RESET_MAGIC,
2662
( hermon->config + HERMON_RESET_OFFSET ) );
2663
mdelay ( HERMON_RESET_WAIT_TIME_MS );
2664
pci_restore ( pci, &backup, backup_exclude );
2666
/* Reset command interface toggle */
2671
* Set up memory protection table
2673
* @v hermon Hermon device
2674
* @ret rc Return status code
2676
static int hermon_setup_mpt ( struct hermon *hermon ) {
2677
struct hermonprm_mpt mpt;
2682
key = ( hermon->cap.reserved_mrws | HERMON_MKEY_PREFIX );
2683
hermon->lkey = ( ( key << 8 ) | ( key >> 24 ) );
2685
/* Initialise memory protection table */
2686
memset ( &mpt, 0, sizeof ( mpt ) );
2687
MLX_FILL_7 ( &mpt, 0,
2695
MLX_FILL_1 ( &mpt, 2, mem_key, key );
2696
MLX_FILL_1 ( &mpt, 3,
2697
pd, HERMON_GLOBAL_PD );
2698
MLX_FILL_1 ( &mpt, 10, len64, 1 );
2699
if ( ( rc = hermon_cmd_sw2hw_mpt ( hermon,
2700
hermon->cap.reserved_mrws,
2702
DBGC ( hermon, "Hermon %p could not set up MPT: %s\n",
2703
hermon, strerror ( rc ) );
2711
* Configure special queue pairs
2713
* @v hermon Hermon device
2714
* @ret rc Return status code
2716
static int hermon_configure_special_qps ( struct hermon *hermon ) {
2719
/* Special QP block must be aligned on its own size */
2720
hermon->special_qpn_base = ( ( hermon->cap.reserved_qps +
2721
HERMON_NUM_SPECIAL_QPS - 1 )
2722
& ~( HERMON_NUM_SPECIAL_QPS - 1 ) );
2723
hermon->qpn_base = ( hermon->special_qpn_base +
2724
HERMON_NUM_SPECIAL_QPS );
2725
DBGC ( hermon, "Hermon %p special QPs at [%lx,%lx]\n", hermon,
2726
hermon->special_qpn_base, ( hermon->qpn_base - 1 ) );
2728
/* Issue command to configure special QPs */
2729
if ( ( rc = hermon_cmd_conf_special_qp ( hermon, 0x00,
2730
hermon->special_qpn_base ) ) != 0 ) {
2731
DBGC ( hermon, "Hermon %p could not configure special QPs: "
2732
"%s\n", hermon, strerror ( rc ) );
2740
* Start Hermon device
2742
* @v hermon Hermon device
2743
* @v running Firmware is already running
2744
* @ret rc Return status code
2746
static int hermon_start ( struct hermon *hermon, int running ) {
2747
struct hermonprm_init_hca init_hca;
2751
/* Start firmware if not already running */
2753
if ( ( rc = hermon_start_firmware ( hermon ) ) != 0 )
2754
goto err_start_firmware;
2757
/* Allocate and map ICM */
2758
memset ( &init_hca, 0, sizeof ( init_hca ) );
2759
if ( ( rc = hermon_map_icm ( hermon, &init_hca ) ) != 0 )
2762
/* Initialise HCA */
2763
MLX_FILL_1 ( &init_hca, 0, version, 0x02 /* "Must be 0x02" */ );
2764
MLX_FILL_1 ( &init_hca, 5, udp, 1 );
2765
MLX_FILL_1 ( &init_hca, 74, uar_parameters.log_max_uars, 8 );
2766
if ( ( rc = hermon_cmd_init_hca ( hermon, &init_hca ) ) != 0 ) {
2767
DBGC ( hermon, "Hermon %p could not initialise HCA: %s\n",
2768
hermon, strerror ( rc ) );
2772
/* Set up memory protection */
2773
if ( ( rc = hermon_setup_mpt ( hermon ) ) != 0 )
2775
for ( i = 0 ; i < hermon->cap.num_ports ; i++ )
2776
hermon->port[i].ibdev->rdma_key = hermon->lkey;
2778
/* Set up event queue */
2779
if ( ( rc = hermon_create_eq ( hermon ) ) != 0 )
2782
/* Configure special QPs */
2783
if ( ( rc = hermon_configure_special_qps ( hermon ) ) != 0 )
2784
goto err_conf_special_qps;
2788
err_conf_special_qps:
2789
hermon_destroy_eq ( hermon );
2792
hermon_cmd_close_hca ( hermon );
2794
hermon_unmap_icm ( hermon );
2796
hermon_stop_firmware ( hermon );
2802
* Stop Hermon device
2804
* @v hermon Hermon device
2806
static void hermon_stop ( struct hermon *hermon ) {
2807
hermon_destroy_eq ( hermon );
2808
hermon_cmd_close_hca ( hermon );
2809
hermon_unmap_icm ( hermon );
2810
hermon_stop_firmware ( hermon );
2811
hermon_reset ( hermon );
2815
* Open Hermon device
2817
* @v hermon Hermon device
2818
* @ret rc Return status code
2820
static int hermon_open ( struct hermon *hermon ) {
2823
/* Start device if applicable */
2824
if ( hermon->open_count == 0 ) {
2825
if ( ( rc = hermon_start ( hermon, 0 ) ) != 0 )
2829
/* Increment open counter */
2830
hermon->open_count++;
2836
* Close Hermon device
2838
* @v hermon Hermon device
2840
static void hermon_close ( struct hermon *hermon ) {
2842
/* Decrement open counter */
2843
assert ( hermon->open_count != 0 );
2844
hermon->open_count--;
2846
/* Stop device if applicable */
2847
if ( hermon->open_count == 0 )
2848
hermon_stop ( hermon );
2851
/***************************************************************************
2853
* Infiniband link-layer operations
2855
***************************************************************************
2859
* Initialise Infiniband link
2861
* @v ibdev Infiniband device
2862
* @ret rc Return status code
2864
static int hermon_ib_open ( struct ib_device *ibdev ) {
2865
struct hermon *hermon = ib_get_drvdata ( ibdev );
2866
union hermonprm_set_port set_port;
2870
if ( ( rc = hermon_open ( hermon ) ) != 0 )
2873
/* Set port parameters */
2874
memset ( &set_port, 0, sizeof ( set_port ) );
2875
MLX_FILL_8 ( &set_port.ib, 0,
2880
mtu_cap, IB_MTU_2048,
2884
MLX_FILL_2 ( &set_port.ib, 10,
2887
MLX_FILL_1 ( &set_port.ib, 28,
2888
link_speed_supported, 1 );
2889
if ( ( rc = hermon_cmd_set_port ( hermon, 0, ibdev->port,
2890
&set_port ) ) != 0 ) {
2891
DBGC ( hermon, "Hermon %p port %d could not set port: %s\n",
2892
hermon, ibdev->port, strerror ( rc ) );
2896
/* Initialise port */
2897
if ( ( rc = hermon_cmd_init_port ( hermon, ibdev->port ) ) != 0 ) {
2898
DBGC ( hermon, "Hermon %p port %d could not initialise port: "
2899
"%s\n", hermon, ibdev->port, strerror ( rc ) );
2903
/* Update MAD parameters */
2904
ib_smc_update ( ibdev, hermon_mad );
2910
hermon_close ( hermon );
2916
* Close Infiniband link
2918
* @v ibdev Infiniband device
2920
static void hermon_ib_close ( struct ib_device *ibdev ) {
2921
struct hermon *hermon = ib_get_drvdata ( ibdev );
2925
if ( ( rc = hermon_cmd_close_port ( hermon, ibdev->port ) ) != 0 ) {
2926
DBGC ( hermon, "Hermon %p port %d could not close port: %s\n",
2927
hermon, ibdev->port, strerror ( rc ) );
2928
/* Nothing we can do about this */
2931
/* Close hardware */
2932
hermon_close ( hermon );
2936
* Inform embedded subnet management agent of a received MAD
2938
* @v ibdev Infiniband device
2940
* @ret rc Return status code
2942
static int hermon_inform_sma ( struct ib_device *ibdev,
2943
union ib_mad *mad ) {
2946
/* Send the MAD to the embedded SMA */
2947
if ( ( rc = hermon_mad ( ibdev, mad ) ) != 0 )
2950
/* Update parameters held in software */
2951
ib_smc_update ( ibdev, hermon_mad );
2956
/***************************************************************************
2958
* Multicast group operations
2960
***************************************************************************
2964
* Attach to multicast group
2966
* @v ibdev Infiniband device
2968
* @v gid Multicast GID
2969
* @ret rc Return status code
2971
static int hermon_mcast_attach ( struct ib_device *ibdev,
2972
struct ib_queue_pair *qp,
2973
union ib_gid *gid ) {
2974
struct hermon *hermon = ib_get_drvdata ( ibdev );
2975
struct hermonprm_mgm_hash hash;
2976
struct hermonprm_mcg_entry mcg;
2980
/* Generate hash table index */
2981
if ( ( rc = hermon_cmd_mgid_hash ( hermon, gid, &hash ) ) != 0 ) {
2982
DBGC ( hermon, "Hermon %p could not hash GID: %s\n",
2983
hermon, strerror ( rc ) );
2986
index = MLX_GET ( &hash, hash );
2988
/* Check for existing hash table entry */
2989
if ( ( rc = hermon_cmd_read_mcg ( hermon, index, &mcg ) ) != 0 ) {
2990
DBGC ( hermon, "Hermon %p could not read MCG %#x: %s\n",
2991
hermon, index, strerror ( rc ) );
2994
if ( MLX_GET ( &mcg, hdr.members_count ) != 0 ) {
2995
/* FIXME: this implementation allows only a single QP
2996
* per multicast group, and doesn't handle hash
2997
* collisions. Sufficient for IPoIB but may need to
2998
* be extended in future.
3000
DBGC ( hermon, "Hermon %p MGID index %#x already in use\n",
3005
/* Update hash table entry */
3006
MLX_FILL_1 ( &mcg, 1, hdr.members_count, 1 );
3007
MLX_FILL_1 ( &mcg, 8, qp[0].qpn, qp->qpn );
3008
memcpy ( &mcg.u.dwords[4], gid, sizeof ( *gid ) );
3009
if ( ( rc = hermon_cmd_write_mcg ( hermon, index, &mcg ) ) != 0 ) {
3010
DBGC ( hermon, "Hermon %p could not write MCG %#x: %s\n",
3011
hermon, index, strerror ( rc ) );
3019
* Detach from multicast group
3021
* @v ibdev Infiniband device
3023
* @v gid Multicast GID
3025
static void hermon_mcast_detach ( struct ib_device *ibdev,
3026
struct ib_queue_pair *qp __unused,
3027
union ib_gid *gid ) {
3028
struct hermon *hermon = ib_get_drvdata ( ibdev );
3029
struct hermonprm_mgm_hash hash;
3030
struct hermonprm_mcg_entry mcg;
3034
/* Generate hash table index */
3035
if ( ( rc = hermon_cmd_mgid_hash ( hermon, gid, &hash ) ) != 0 ) {
3036
DBGC ( hermon, "Hermon %p could not hash GID: %s\n",
3037
hermon, strerror ( rc ) );
3040
index = MLX_GET ( &hash, hash );
3042
/* Clear hash table entry */
3043
memset ( &mcg, 0, sizeof ( mcg ) );
3044
if ( ( rc = hermon_cmd_write_mcg ( hermon, index, &mcg ) ) != 0 ) {
3045
DBGC ( hermon, "Hermon %p could not write MCG %#x: %s\n",
3046
hermon, index, strerror ( rc ) );
3051
/** Hermon Infiniband operations */
3052
static struct ib_device_operations hermon_ib_operations = {
3053
.create_cq = hermon_create_cq,
3054
.destroy_cq = hermon_destroy_cq,
3055
.create_qp = hermon_create_qp,
3056
.modify_qp = hermon_modify_qp,
3057
.destroy_qp = hermon_destroy_qp,
3058
.post_send = hermon_post_send,
3059
.post_recv = hermon_post_recv,
3060
.poll_cq = hermon_poll_cq,
3061
.poll_eq = hermon_poll_eq,
3062
.open = hermon_ib_open,
3063
.close = hermon_ib_close,
3064
.mcast_attach = hermon_mcast_attach,
3065
.mcast_detach = hermon_mcast_detach,
3066
.set_port_info = hermon_inform_sma,
3067
.set_pkey_table = hermon_inform_sma,
3071
* Register Hermon Infiniband device
3073
* @v hermon Hermon device
3074
* @v port Hermon port
3075
* @ret rc Return status code
3077
static int hermon_register_ibdev ( struct hermon *hermon,
3078
struct hermon_port *port ) {
3079
struct ib_device *ibdev = port->ibdev;
3082
/* Initialise parameters using SMC */
3083
ib_smc_init ( ibdev, hermon_mad );
3085
/* Register Infiniband device */
3086
if ( ( rc = register_ibdev ( ibdev ) ) != 0 ) {
3087
DBGC ( hermon, "Hermon %p port %d could not register IB "
3088
"device: %s\n", hermon, ibdev->port, strerror ( rc ) );
3096
* Handle Hermon Infiniband device port state change
3098
* @v hermon Hermon device
3099
* @v port Hermon port
3100
* @v link_up Link is up
3102
static void hermon_state_change_ibdev ( struct hermon *hermon __unused,
3103
struct hermon_port *port,
3104
int link_up __unused ) {
3105
struct ib_device *ibdev = port->ibdev;
3107
/* Update MAD parameters */
3108
ib_smc_update ( ibdev, hermon_mad );
3112
* Unregister Hermon Infiniband device
3114
* @v hermon Hermon device
3115
* @v port Hermon port
3117
static void hermon_unregister_ibdev ( struct hermon *hermon __unused,
3118
struct hermon_port *port ) {
3119
struct ib_device *ibdev = port->ibdev;
3121
unregister_ibdev ( ibdev );
3124
/** Hermon Infiniband port type */
3125
static struct hermon_port_type hermon_port_type_ib = {
3126
.register_dev = hermon_register_ibdev,
3127
.state_change = hermon_state_change_ibdev,
3128
.unregister_dev = hermon_unregister_ibdev,
3131
/***************************************************************************
3133
* Ethernet operation
3135
***************************************************************************
3138
/** Number of Hermon Ethernet send work queue entries */
3139
#define HERMON_ETH_NUM_SEND_WQES 2
3141
/** Number of Hermon Ethernet receive work queue entries */
3142
#define HERMON_ETH_NUM_RECV_WQES 4
3144
/** Number of Hermon Ethernet completion entries */
3145
#define HERMON_ETH_NUM_CQES 8
3148
* Transmit packet via Hermon Ethernet device
3150
* @v netdev Network device
3151
* @v iobuf I/O buffer
3152
* @ret rc Return status code
3154
static int hermon_eth_transmit ( struct net_device *netdev,
3155
struct io_buffer *iobuf ) {
3156
struct hermon_port *port = netdev->priv;
3157
struct ib_device *ibdev = port->ibdev;
3158
struct hermon *hermon = ib_get_drvdata ( ibdev );
3161
/* Transmit packet */
3162
if ( ( rc = ib_post_send ( ibdev, port->eth_qp, NULL,
3164
DBGC ( hermon, "Hermon %p port %d could not transmit: %s\n",
3165
hermon, ibdev->port, strerror ( rc ) );
3172
/** Hermon Ethernet queue pair operations */
3173
static struct ib_queue_pair_operations hermon_eth_qp_op = {
3174
.alloc_iob = alloc_iob,
3178
* Handle Hermon Ethernet device send completion
3180
* @v ibdev Infiniband device
3182
* @v iobuf I/O buffer
3183
* @v rc Completion status code
3185
static void hermon_eth_complete_send ( struct ib_device *ibdev __unused,
3186
struct ib_queue_pair *qp,
3187
struct io_buffer *iobuf, int rc ) {
3188
struct net_device *netdev = ib_qp_get_ownerdata ( qp );
3190
netdev_tx_complete_err ( netdev, iobuf, rc );
3194
* Handle Hermon Ethernet device receive completion
3196
* @v ibdev Infiniband device
3198
* @v dest Destination address vector, or NULL
3199
* @v source Source address vector, or NULL
3200
* @v iobuf I/O buffer
3201
* @v rc Completion status code
3203
static void hermon_eth_complete_recv ( struct ib_device *ibdev __unused,
3204
struct ib_queue_pair *qp,
3205
struct ib_address_vector *dest __unused,
3206
struct ib_address_vector *source,
3207
struct io_buffer *iobuf, int rc ) {
3208
struct net_device *netdev = ib_qp_get_ownerdata ( qp );
3209
struct net_device *vlan;
3211
/* Find VLAN device, if applicable */
3212
if ( source->vlan_present ) {
3213
if ( ( vlan = vlan_find ( netdev, source->vlan ) ) != NULL ) {
3215
} else if ( rc == 0 ) {
3220
/* Hand off to network layer */
3222
netdev_rx ( netdev, iobuf );
3224
netdev_rx_err ( netdev, iobuf, rc );
3228
/** Hermon Ethernet device completion operations */
3229
static struct ib_completion_queue_operations hermon_eth_cq_op = {
3230
.complete_send = hermon_eth_complete_send,
3231
.complete_recv = hermon_eth_complete_recv,
3235
* Poll Hermon Ethernet device
3237
* @v netdev Network device
3239
static void hermon_eth_poll ( struct net_device *netdev ) {
3240
struct hermon_port *port = netdev->priv;
3241
struct ib_device *ibdev = port->ibdev;
3243
ib_poll_eq ( ibdev );
3247
* Open Hermon Ethernet device
3249
* @v netdev Network device
3250
* @ret rc Return status code
3252
static int hermon_eth_open ( struct net_device *netdev ) {
3253
struct hermon_port *port = netdev->priv;
3254
struct ib_device *ibdev = port->ibdev;
3255
struct hermon *hermon = ib_get_drvdata ( ibdev );
3256
union hermonprm_set_port set_port;
3260
if ( ( rc = hermon_open ( hermon ) ) != 0 )
3263
/* Allocate completion queue */
3264
port->eth_cq = ib_create_cq ( ibdev, HERMON_ETH_NUM_CQES,
3265
&hermon_eth_cq_op );
3266
if ( ! port->eth_cq ) {
3267
DBGC ( hermon, "Hermon %p port %d could not create completion "
3268
"queue\n", hermon, ibdev->port );
3273
/* Allocate queue pair */
3274
port->eth_qp = ib_create_qp ( ibdev, IB_QPT_ETH,
3275
HERMON_ETH_NUM_SEND_WQES, port->eth_cq,
3276
HERMON_ETH_NUM_RECV_WQES, port->eth_cq,
3277
&hermon_eth_qp_op, netdev->name );
3278
if ( ! port->eth_qp ) {
3279
DBGC ( hermon, "Hermon %p port %d could not create queue "
3280
"pair\n", hermon, ibdev->port );
3284
ib_qp_set_ownerdata ( port->eth_qp, netdev );
3286
/* Activate queue pair */
3287
if ( ( rc = ib_modify_qp ( ibdev, port->eth_qp ) ) != 0 ) {
3288
DBGC ( hermon, "Hermon %p port %d could not modify queue "
3289
"pair: %s\n", hermon, ibdev->port, strerror ( rc ) );
3293
/* Fill receive rings */
3294
ib_refill_recv ( ibdev, port->eth_qp );
3296
/* Set port general parameters */
3297
memset ( &set_port, 0, sizeof ( set_port ) );
3298
MLX_FILL_3 ( &set_port.general, 0,
3302
MLX_FILL_1 ( &set_port.general, 1,
3303
mtu, ( ETH_FRAME_LEN + 40 /* Used by card */ ) );
3304
MLX_FILL_1 ( &set_port.general, 2,
3305
pfctx, ( 1 << FCOE_VLAN_PRIORITY ) );
3306
MLX_FILL_1 ( &set_port.general, 3,
3307
pfcrx, ( 1 << FCOE_VLAN_PRIORITY ) );
3308
if ( ( rc = hermon_cmd_set_port ( hermon, 1,
3309
( HERMON_SET_PORT_GENERAL_PARAM |
3311
&set_port ) ) != 0 ) {
3312
DBGC ( hermon, "Hermon %p port %d could not set port general "
3314
hermon, ibdev->port, strerror ( rc ) );
3315
goto err_set_port_general_params;
3318
/* Set port receive QP */
3319
memset ( &set_port, 0, sizeof ( set_port ) );
3320
MLX_FILL_1 ( &set_port.rqp_calc, 0, base_qpn, port->eth_qp->qpn );
3321
MLX_FILL_1 ( &set_port.rqp_calc, 2,
3322
mac_miss_index, 128 /* MAC misses go to promisc QP */ );
3323
MLX_FILL_2 ( &set_port.rqp_calc, 3,
3324
vlan_miss_index, 127 /* VLAN misses go to promisc QP */,
3325
no_vlan_index, 126 /* VLAN-free go to promisc QP */ );
3326
MLX_FILL_2 ( &set_port.rqp_calc, 5,
3327
promisc_qpn, port->eth_qp->qpn,
3329
MLX_FILL_2 ( &set_port.rqp_calc, 6,
3330
def_mcast_qpn, port->eth_qp->qpn,
3331
mc_promisc_mode, 2 /* Receive all multicasts */ );
3332
if ( ( rc = hermon_cmd_set_port ( hermon, 1,
3333
( HERMON_SET_PORT_RECEIVE_QP |
3335
&set_port ) ) != 0 ) {
3336
DBGC ( hermon, "Hermon %p port %d could not set port receive "
3337
"QP: %s\n", hermon, ibdev->port, strerror ( rc ) );
3338
goto err_set_port_receive_qp;
3341
/* Initialise port */
3342
if ( ( rc = hermon_cmd_init_port ( hermon, ibdev->port ) ) != 0 ) {
3343
DBGC ( hermon, "Hermon %p port %d could not initialise port: "
3344
"%s\n", hermon, ibdev->port, strerror ( rc ) );
3351
err_set_port_receive_qp:
3352
err_set_port_general_params:
3354
ib_destroy_qp ( ibdev, port->eth_qp );
3356
ib_destroy_cq ( ibdev, port->eth_cq );
3358
hermon_close ( hermon );
3364
* Close Hermon Ethernet device
3366
* @v netdev Network device
3368
static void hermon_eth_close ( struct net_device *netdev ) {
3369
struct hermon_port *port = netdev->priv;
3370
struct ib_device *ibdev = port->ibdev;
3371
struct hermon *hermon = ib_get_drvdata ( ibdev );
3375
if ( ( rc = hermon_cmd_close_port ( hermon, ibdev->port ) ) != 0 ) {
3376
DBGC ( hermon, "Hermon %p port %d could not close port: %s\n",
3377
hermon, ibdev->port, strerror ( rc ) );
3378
/* Nothing we can do about this */
3381
/* Tear down the queues */
3382
ib_destroy_qp ( ibdev, port->eth_qp );
3383
ib_destroy_cq ( ibdev, port->eth_cq );
3385
/* Close hardware */
3386
hermon_close ( hermon );
3389
/** Hermon Ethernet network device operations */
3390
static struct net_device_operations hermon_eth_operations = {
3391
.open = hermon_eth_open,
3392
.close = hermon_eth_close,
3393
.transmit = hermon_eth_transmit,
3394
.poll = hermon_eth_poll,
3398
* Register Hermon Ethernet device
3400
* @v hermon Hermon device
3401
* @v port Hermon port
3402
* @ret rc Return status code
3404
static int hermon_register_netdev ( struct hermon *hermon,
3405
struct hermon_port *port ) {
3406
struct net_device *netdev = port->netdev;
3407
struct ib_device *ibdev = port->ibdev;
3408
struct hermonprm_query_port_cap query_port;
3415
/* Retrieve MAC address */
3416
if ( ( rc = hermon_cmd_query_port ( hermon, ibdev->port,
3417
&query_port ) ) != 0 ) {
3418
DBGC ( hermon, "Hermon %p port %d could not query port: %s\n",
3419
hermon, ibdev->port, strerror ( rc ) );
3420
goto err_query_port;
3422
mac.dwords[0] = htonl ( MLX_GET ( &query_port, mac_47_32 ) );
3423
mac.dwords[1] = htonl ( MLX_GET ( &query_port, mac_31_0 ) );
3424
memcpy ( netdev->hw_addr,
3425
&mac.bytes[ sizeof ( mac.bytes ) - ETH_ALEN ], ETH_ALEN );
3427
/* Register network device */
3428
if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
3429
DBGC ( hermon, "Hermon %p port %d could not register network "
3430
"device: %s\n", hermon, ibdev->port, strerror ( rc ) );
3431
goto err_register_netdev;
3434
/* Register non-volatile options */
3435
if ( ( rc = register_nvo ( &port->nvo,
3436
netdev_settings ( netdev ) ) ) != 0 ) {
3437
DBGC ( hermon, "Hermon %p port %d could not register non-"
3438
"volatile options: %s\n",
3439
hermon, ibdev->port, strerror ( rc ) );
3440
goto err_register_nvo;
3445
unregister_nvo ( &port->nvo );
3447
unregister_netdev ( netdev );
3448
err_register_netdev:
3454
* Handle Hermon Ethernet device port state change
3456
* @v hermon Hermon device
3457
* @v port Hermon port
3458
* @v link_up Link is up
3460
static void hermon_state_change_netdev ( struct hermon *hermon __unused,
3461
struct hermon_port *port,
3463
struct net_device *netdev = port->netdev;
3466
netdev_link_up ( netdev );
3468
netdev_link_down ( netdev );
3473
* Unregister Hermon Ethernet device
3475
* @v hermon Hermon device
3476
* @v port Hermon port
3478
static void hermon_unregister_netdev ( struct hermon *hermon __unused,
3479
struct hermon_port *port ) {
3480
struct net_device *netdev = port->netdev;
3482
unregister_nvo ( &port->nvo );
3483
unregister_netdev ( netdev );
3486
/** Hermon Ethernet port type */
3487
static struct hermon_port_type hermon_port_type_eth = {
3488
.register_dev = hermon_register_netdev,
3489
.state_change = hermon_state_change_netdev,
3490
.unregister_dev = hermon_unregister_netdev,
3493
/***************************************************************************
3495
* Port type detection
3497
***************************************************************************
3500
/** Timeout for port sensing */
3501
#define HERMON_SENSE_PORT_TIMEOUT ( TICKS_PER_SEC / 2 )
3506
* @v port_type Port type
3507
* @v port_type_name Port type name
3509
static inline const char * hermon_name_port_type ( unsigned int port_type ) {
3510
switch ( port_type ) {
3511
case HERMON_PORT_TYPE_UNKNOWN: return "unknown";
3512
case HERMON_PORT_TYPE_IB: return "Infiniband";
3513
case HERMON_PORT_TYPE_ETH: return "Ethernet";
3514
default: return "INVALID";
3521
* @v hermon Hermon device
3522
* @v port Hermon port
3523
* @ret port_type Port type, or negative error
3525
static int hermon_sense_port_type ( struct hermon *hermon,
3526
struct hermon_port *port ) {
3527
struct ib_device *ibdev = port->ibdev;
3528
struct hermonprm_sense_port sense_port;
3532
/* If DPDP is not supported, always assume Infiniband */
3533
if ( ! hermon->cap.dpdp ) {
3534
port_type = HERMON_PORT_TYPE_IB;
3535
DBGC ( hermon, "Hermon %p port %d does not support DPDP; "
3536
"assuming an %s network\n", hermon, ibdev->port,
3537
hermon_name_port_type ( port_type ) );
3541
/* Sense the port type */
3542
if ( ( rc = hermon_cmd_sense_port ( hermon, ibdev->port,
3543
&sense_port ) ) != 0 ) {
3544
DBGC ( hermon, "Hermon %p port %d sense failed: %s\n",
3545
hermon, ibdev->port, strerror ( rc ) );
3548
port_type = MLX_GET ( &sense_port, port_type );
3550
DBGC ( hermon, "Hermon %p port %d sensed an %s network\n",
3551
hermon, ibdev->port, hermon_name_port_type ( port_type ) );
3558
* @v hermon Hermon device
3559
* @v port Hermon port
3560
* @ret rc Return status code
3562
static int hermon_set_port_type ( struct hermon *hermon,
3563
struct hermon_port *port ) {
3564
struct ib_device *ibdev = port->ibdev;
3565
struct hermonprm_query_port_cap query_port;
3569
unsigned long start;
3570
unsigned long elapsed;
3573
/* Check to see which types are supported */
3574
if ( ( rc = hermon_cmd_query_port ( hermon, ibdev->port,
3575
&query_port ) ) != 0 ) {
3576
DBGC ( hermon, "Hermon %p port %d could not query port: %s\n",
3577
hermon, ibdev->port, strerror ( rc ) );
3580
ib_supported = MLX_GET ( &query_port, ib );
3581
eth_supported = MLX_GET ( &query_port, eth );
3582
DBGC ( hermon, "Hermon %p port %d supports%s%s%s\n",
3583
hermon, ibdev->port, ( ib_supported ? " Infiniband" : "" ),
3584
( ( ib_supported && eth_supported ) ? " and" : "" ),
3585
( eth_supported ? " Ethernet" : "" ) );
3587
/* Sense network, if applicable */
3588
if ( ib_supported && eth_supported ) {
3590
/* Both types are supported; try sensing network */
3591
start = currticks();
3593
/* Try sensing port */
3594
port_type = hermon_sense_port_type ( hermon, port );
3595
if ( port_type < 0 ) {
3599
} while ( ( port_type == HERMON_PORT_TYPE_UNKNOWN ) &&
3600
( ( elapsed = ( currticks() - start ) ) <
3601
HERMON_SENSE_PORT_TIMEOUT ) );
3603
/* Set port type based on sensed network, defaulting
3604
* to Infiniband if nothing was sensed.
3606
switch ( port_type ) {
3607
case HERMON_PORT_TYPE_ETH:
3608
port->type = &hermon_port_type_eth;
3610
case HERMON_PORT_TYPE_IB:
3611
case HERMON_PORT_TYPE_UNKNOWN:
3612
port->type = &hermon_port_type_ib;
3618
} else if ( eth_supported ) {
3619
port->type = &hermon_port_type_eth;
3621
port->type = &hermon_port_type_ib;
3624
assert ( port->type != NULL );
3628
/***************************************************************************
3632
***************************************************************************
3636
* Harvest Ethernet MAC for BOFM
3638
* @v bofm BOFM device
3639
* @v mport Multi-port index
3640
* @v mac MAC to fill in
3641
* @ret rc Return status code
3643
static int hermon_bofm_harvest ( struct bofm_device *bofm, unsigned int mport,
3645
struct hermon *hermon = container_of ( bofm, struct hermon, bofm );
3646
struct hermonprm_mod_stat_cfg stat_cfg;
3653
/* Query static configuration */
3654
if ( ( rc = hermon_mod_stat_cfg ( hermon, mport,
3655
HERMON_MOD_STAT_CFG_QUERY,
3656
HERMON_MOD_STAT_CFG_OFFSET ( mac_m ),
3657
&stat_cfg ) ) != 0 ) {
3658
DBGC ( hermon, "Hermon %p port %d could not query "
3659
"configuration: %s\n", hermon, mport, strerror ( rc ) );
3663
/* Retrieve MAC address */
3664
buf.dwords[0] = htonl ( MLX_GET ( &stat_cfg, mac_high ) );
3665
buf.dwords[1] = htonl ( MLX_GET ( &stat_cfg, mac_low ) );
3666
memcpy ( mac, &buf.bytes[ sizeof ( buf.bytes ) - ETH_ALEN ],
3669
DBGC ( hermon, "Hermon %p port %d harvested MAC address %s\n",
3670
hermon, mport, eth_ntoa ( mac ) );
3676
* Update Ethernet MAC for BOFM
3678
* @v bofm BOFM device
3679
* @v mport Multi-port index
3680
* @v mac MAC to fill in
3681
* @ret rc Return status code
3683
static int hermon_bofm_update ( struct bofm_device *bofm, unsigned int mport,
3684
const uint8_t *mac ) {
3685
struct hermon *hermon = container_of ( bofm, struct hermon, bofm );
3686
struct hermonprm_mod_stat_cfg stat_cfg;
3693
/* Prepare MAC address */
3694
memset ( &buf, 0, sizeof ( buf ) );
3695
memcpy ( &buf.bytes[ sizeof ( buf.bytes ) - ETH_ALEN ], mac,
3698
/* Modify static configuration */
3699
memset ( &stat_cfg, 0, sizeof ( stat_cfg ) );
3700
MLX_FILL_2 ( &stat_cfg, 36,
3702
mac_high, ntohl ( buf.dwords[0] ) );
3703
MLX_FILL_1 ( &stat_cfg, 37, mac_low, ntohl ( buf.dwords[1] ) );
3704
if ( ( rc = hermon_mod_stat_cfg ( hermon, mport,
3705
HERMON_MOD_STAT_CFG_SET,
3706
HERMON_MOD_STAT_CFG_OFFSET ( mac_m ),
3707
&stat_cfg ) ) != 0 ) {
3708
DBGC ( hermon, "Hermon %p port %d could not modify "
3709
"configuration: %s\n", hermon, mport, strerror ( rc ) );
3713
DBGC ( hermon, "Hermon %p port %d updated MAC address to %s\n",
3714
hermon, mport, eth_ntoa ( mac ) );
3719
/** Hermon BOFM operations */
3720
static struct bofm_operations hermon_bofm_operations = {
3721
.harvest = hermon_bofm_harvest,
3722
.update = hermon_bofm_update,
3725
/***************************************************************************
3729
***************************************************************************
3733
* Allocate Hermon device
3737
* @ret rc Return status code
3739
static struct hermon * hermon_alloc ( void ) {
3740
struct hermon *hermon;
3742
/* Allocate Hermon device */
3743
hermon = zalloc ( sizeof ( *hermon ) );
3747
/* Allocate space for mailboxes */
3748
hermon->mailbox_in = malloc_dma ( HERMON_MBOX_SIZE,
3749
HERMON_MBOX_ALIGN );
3750
if ( ! hermon->mailbox_in )
3751
goto err_mailbox_in;
3752
hermon->mailbox_out = malloc_dma ( HERMON_MBOX_SIZE,
3753
HERMON_MBOX_ALIGN );
3754
if ( ! hermon->mailbox_out )
3755
goto err_mailbox_out;
3759
free_dma ( hermon->mailbox_out, HERMON_MBOX_SIZE );
3761
free_dma ( hermon->mailbox_in, HERMON_MBOX_SIZE );
3769
* Free Hermon device
3771
* @v hermon Hermon device
3773
static void hermon_free ( struct hermon *hermon ) {
3775
ufree ( hermon->icm );
3776
ufree ( hermon->firmware_area );
3777
free_dma ( hermon->mailbox_out, HERMON_MBOX_SIZE );
3778
free_dma ( hermon->mailbox_in, HERMON_MBOX_SIZE );
3787
* @ret rc Return status code
3789
static int hermon_probe ( struct pci_device *pci ) {
3790
struct hermon *hermon;
3791
struct ib_device *ibdev;
3792
struct net_device *netdev;
3793
struct hermon_port *port;
3797
/* Allocate Hermon device */
3798
hermon = hermon_alloc();
3803
pci_set_drvdata ( pci, hermon );
3806
/* Fix up PCI device */
3807
adjust_pci_device ( pci );
3810
hermon->config = ioremap ( pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR ),
3811
HERMON_PCI_CONFIG_BAR_SIZE );
3812
hermon->uar = ioremap ( pci_bar_start ( pci, HERMON_PCI_UAR_BAR ),
3813
HERMON_UAR_NON_EQ_PAGE * HERMON_PAGE_SIZE );
3816
hermon_reset ( hermon );
3818
/* Start firmware */
3819
if ( ( rc = hermon_start_firmware ( hermon ) ) != 0 )
3820
goto err_start_firmware;
3822
/* Get device limits */
3823
if ( ( rc = hermon_get_cap ( hermon ) ) != 0 )
3826
/* Allocate Infiniband devices */
3827
for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
3828
ibdev = alloc_ibdev ( 0 );
3831
goto err_alloc_ibdev;
3833
hermon->port[i].ibdev = ibdev;
3834
ibdev->op = &hermon_ib_operations;
3835
ibdev->dev = &pci->dev;
3836
ibdev->port = ( HERMON_PORT_BASE + i );
3837
ib_set_drvdata ( ibdev, hermon );
3840
/* Allocate network devices */
3841
for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
3842
netdev = alloc_etherdev ( 0 );
3845
goto err_alloc_netdev;
3847
hermon->port[i].netdev = netdev;
3848
netdev_init ( netdev, &hermon_eth_operations );
3849
netdev->dev = &pci->dev;
3850
netdev->priv = &hermon->port[i];
3854
if ( ( rc = hermon_start ( hermon, 1 ) ) != 0 )
3857
/* Determine port types */
3858
for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
3859
port = &hermon->port[i];
3860
if ( ( rc = hermon_set_port_type ( hermon, port ) ) != 0 )
3861
goto err_set_port_type;
3864
/* Initialise non-volatile storage */
3865
nvs_vpd_init ( &hermon->nvsvpd, pci );
3866
for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
3867
port = &hermon->port[i];
3868
nvs_vpd_nvo_init ( &hermon->nvsvpd,
3869
HERMON_VPD_FIELD ( port->ibdev->port ),
3873
/* Register devices */
3874
for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
3875
port = &hermon->port[i];
3876
if ( ( rc = port->type->register_dev ( hermon, port ) ) != 0 )
3880
/* Leave device quiescent until opened */
3881
if ( hermon->open_count == 0 )
3882
hermon_stop ( hermon );
3886
i = hermon->cap.num_ports;
3888
for ( i-- ; ( signed int ) i >= 0 ; i-- ) {
3889
port = &hermon->port[i];
3890
port->type->unregister_dev ( hermon, port );
3893
hermon_stop ( hermon );
3895
i = hermon->cap.num_ports;
3897
for ( i-- ; ( signed int ) i >= 0 ; i-- ) {
3898
netdev_nullify ( hermon->port[i].netdev );
3899
netdev_put ( hermon->port[i].netdev );
3901
i = hermon->cap.num_ports;
3903
for ( i-- ; ( signed int ) i >= 0 ; i-- )
3904
ibdev_put ( hermon->port[i].ibdev );
3906
hermon_stop_firmware ( hermon );
3908
iounmap ( hermon->uar );
3909
iounmap ( hermon->config );
3910
hermon_free ( hermon );
3920
static void hermon_remove ( struct pci_device *pci ) {
3921
struct hermon *hermon = pci_get_drvdata ( pci );
3922
struct hermon_port *port;
3925
for ( i = ( hermon->cap.num_ports - 1 ) ; i >= 0 ; i-- ) {
3926
port = &hermon->port[i];
3927
port->type->unregister_dev ( hermon, port );
3929
for ( i = ( hermon->cap.num_ports - 1 ) ; i >= 0 ; i-- ) {
3930
netdev_nullify ( hermon->port[i].netdev );
3931
netdev_put ( hermon->port[i].netdev );
3933
for ( i = ( hermon->cap.num_ports - 1 ) ; i >= 0 ; i-- )
3934
ibdev_put ( hermon->port[i].ibdev );
3935
iounmap ( hermon->uar );
3936
iounmap ( hermon->config );
3937
hermon_free ( hermon );
3941
* Probe PCI device for BOFM
3945
* @ret rc Return status code
3947
static int hermon_bofm_probe ( struct pci_device *pci ) {
3948
struct hermon *hermon;
3951
/* Allocate Hermon device */
3952
hermon = hermon_alloc();
3957
pci_set_drvdata ( pci, hermon );
3960
/* Fix up PCI device */
3961
adjust_pci_device ( pci );
3964
hermon->config = ioremap ( pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR ),
3965
HERMON_PCI_CONFIG_BAR_SIZE );
3967
/* Initialise BOFM device */
3968
bofm_init ( &hermon->bofm, pci, &hermon_bofm_operations );
3970
/* Register BOFM device */
3971
if ( ( rc = bofm_register ( &hermon->bofm ) ) != 0 ) {
3972
DBGC ( hermon, "Hermon %p could not register BOFM device: "
3973
"%s\n", hermon, strerror ( rc ) );
3974
goto err_bofm_register;
3980
iounmap ( hermon->config );
3981
hermon_free ( hermon );
3987
* Remove PCI device for BOFM
3991
static void hermon_bofm_remove ( struct pci_device *pci ) {
3992
struct hermon *hermon = pci_get_drvdata ( pci );
3994
bofm_unregister ( &hermon->bofm );
3995
iounmap ( hermon->config );
3996
hermon_free ( hermon );
3999
static struct pci_device_id hermon_nics[] = {
4000
PCI_ROM ( 0x15b3, 0x6340, "mt25408", "MT25408 HCA driver", 0 ),
4001
PCI_ROM ( 0x15b3, 0x634a, "mt25418", "MT25418 HCA driver", 0 ),
4002
PCI_ROM ( 0x15b3, 0x6732, "mt26418", "MT26418 HCA driver", 0 ),
4003
PCI_ROM ( 0x15b3, 0x673c, "mt26428", "MT26428 HCA driver", 0 ),
4004
PCI_ROM ( 0x15b3, 0x6746, "mt26438", "MT26438 HCA driver", 0 ),
4005
PCI_ROM ( 0x15b3, 0x6778, "mt26488", "MT26488 HCA driver", 0 ),
4006
PCI_ROM ( 0x15b3, 0x6368, "mt25448", "MT25448 HCA driver", 0 ),
4007
PCI_ROM ( 0x15b3, 0x6750, "mt26448", "MT26448 HCA driver", 0 ),
4008
PCI_ROM ( 0x15b3, 0x6372, "mt25458", "MT25458 HCA driver", 0 ),
4009
PCI_ROM ( 0x15b3, 0x675a, "mt26458", "MT26458 HCA driver", 0 ),
4010
PCI_ROM ( 0x15b3, 0x6764, "mt26468", "MT26468 HCA driver", 0 ),
4011
PCI_ROM ( 0x15b3, 0x676e, "mt26478", "MT26478 HCA driver", 0 ),
4014
struct pci_driver hermon_driver __pci_driver = {
4016
.id_count = ( sizeof ( hermon_nics ) / sizeof ( hermon_nics[0] ) ),
4017
.probe = hermon_probe,
4018
.remove = hermon_remove,
4021
struct pci_driver hermon_bofm_driver __bofm_driver = {
4023
.id_count = ( sizeof ( hermon_nics ) / sizeof ( hermon_nics[0] ) ),
4024
.probe = hermon_bofm_probe,
4025
.remove = hermon_bofm_remove,