~ubuntu-branches/ubuntu/raring/ipxe/raring

« back to all changes in this revision

Viewing changes to src/drivers/infiniband/hermon.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-11-14 15:47:31 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20121114154731-jhuy5d1h2jw75qe9
Tags: 1.0.0+git-4.d6b0b76-0ubuntu1
* New upstream snapshot:
  - d/p/iscsi*.patch: Dropped - included in snapshot.
  - Refreshed all other patches.
* d/p/enable-https.patch: Enable HTTPS support (LP: #1025239).

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
18
 * 02110-1301, USA.
18
19
 */
19
20
 
20
21
FILE_LICENCE ( GPL2_OR_LATER );
41
42
#include <ipxe/fcoe.h>
42
43
#include <ipxe/vlan.h>
43
44
#include <ipxe/bofm.h>
 
45
#include <ipxe/nvsvpd.h>
 
46
#include <ipxe/nvo.h>
44
47
#include "hermon.h"
45
48
 
46
49
/**
1363
1366
 *
1364
1367
 * @v ibdev             Infiniband device
1365
1368
 * @v qp                Queue pair
1366
 
 * @v av                Address vector
 
1369
 * @v dest              Destination address vector
1367
1370
 * @v iobuf             I/O buffer
1368
1371
 * @v wqe               Send work queue entry
1369
1372
 * @ret opcode          Control opcode
1371
1374
static __attribute__ (( unused )) unsigned int
1372
1375
hermon_fill_nop_send_wqe ( struct ib_device *ibdev __unused,
1373
1376
                           struct ib_queue_pair *qp __unused,
1374
 
                           struct ib_address_vector *av __unused,
 
1377
                           struct ib_address_vector *dest __unused,
1375
1378
                           struct io_buffer *iobuf __unused,
1376
1379
                           union hermon_send_wqe *wqe ) {
1377
1380
 
1385
1388
 *
1386
1389
 * @v ibdev             Infiniband device
1387
1390
 * @v qp                Queue pair
1388
 
 * @v av                Address vector
 
1391
 * @v dest              Destination address vector
1389
1392
 * @v iobuf             I/O buffer
1390
1393
 * @v wqe               Send work queue entry
1391
1394
 * @ret opcode          Control opcode
1393
1396
static unsigned int
1394
1397
hermon_fill_ud_send_wqe ( struct ib_device *ibdev,
1395
1398
                          struct ib_queue_pair *qp __unused,
1396
 
                          struct ib_address_vector *av,
 
1399
                          struct ib_address_vector *dest,
1397
1400
                          struct io_buffer *iobuf,
1398
1401
                          union hermon_send_wqe *wqe ) {
1399
1402
        struct hermon *hermon = ib_get_drvdata ( ibdev );
1405
1408
                     ud_address_vector.pd, HERMON_GLOBAL_PD,
1406
1409
                     ud_address_vector.port_number, ibdev->port );
1407
1410
        MLX_FILL_2 ( &wqe->ud.ud, 1,
1408
 
                     ud_address_vector.rlid, av->lid,
1409
 
                     ud_address_vector.g, av->gid_present );
 
1411
                     ud_address_vector.rlid, dest->lid,
 
1412
                     ud_address_vector.g, dest->gid_present );
1410
1413
        MLX_FILL_1 ( &wqe->ud.ud, 2,
1411
 
                     ud_address_vector.max_stat_rate, hermon_rate ( av ) );
1412
 
        MLX_FILL_1 ( &wqe->ud.ud, 3, ud_address_vector.sl, av->sl );
1413
 
        memcpy ( &wqe->ud.ud.u.dwords[4], &av->gid, sizeof ( av->gid ) );
1414
 
        MLX_FILL_1 ( &wqe->ud.ud, 8, destination_qp, av->qpn );
1415
 
        MLX_FILL_1 ( &wqe->ud.ud, 9, q_key, av->qkey );
 
1414
                     ud_address_vector.max_stat_rate, hermon_rate ( dest ) );
 
1415
        MLX_FILL_1 ( &wqe->ud.ud, 3, ud_address_vector.sl, dest->sl );
 
1416
        memcpy ( &wqe->ud.ud.u.dwords[4], &dest->gid, sizeof ( dest->gid ) );
 
1417
        MLX_FILL_1 ( &wqe->ud.ud, 8, destination_qp, dest->qpn );
 
1418
        MLX_FILL_1 ( &wqe->ud.ud, 9, q_key, dest->qkey );
1416
1419
        MLX_FILL_1 ( &wqe->ud.data[0], 0, byte_count, iob_len ( iobuf ) );
1417
1420
        MLX_FILL_1 ( &wqe->ud.data[0], 1, l_key, hermon->lkey );
1418
1421
        MLX_FILL_H ( &wqe->ud.data[0], 2,
1427
1430
 *
1428
1431
 * @v ibdev             Infiniband device
1429
1432
 * @v qp                Queue pair
1430
 
 * @v av                Address vector
 
1433
 * @v dest              Destination address vector
1431
1434
 * @v iobuf             I/O buffer
1432
1435
 * @v wqe               Send work queue entry
1433
1436
 * @ret opcode          Control opcode
1435
1438
static unsigned int
1436
1439
hermon_fill_mlx_send_wqe ( struct ib_device *ibdev,
1437
1440
                           struct ib_queue_pair *qp,
1438
 
                           struct ib_address_vector *av,
 
1441
                           struct ib_address_vector *dest,
1439
1442
                           struct io_buffer *iobuf,
1440
1443
                           union hermon_send_wqe *wqe ) {
1441
1444
        struct hermon *hermon = ib_get_drvdata ( ibdev );
1445
1448
        iob_populate ( &headers, &wqe->mlx.headers, 0,
1446
1449
                       sizeof ( wqe->mlx.headers ) );
1447
1450
        iob_reserve ( &headers, sizeof ( wqe->mlx.headers ) );
1448
 
        ib_push ( ibdev, &headers, qp, iob_len ( iobuf ), av );
 
1451
        ib_push ( ibdev, &headers, qp, iob_len ( iobuf ), dest );
1449
1452
 
1450
1453
        /* Fill work queue entry */
1451
1454
        MLX_FILL_1 ( &wqe->mlx.ctrl, 1, ds,
1453
1456
        MLX_FILL_5 ( &wqe->mlx.ctrl, 2,
1454
1457
                     c, 0x03 /* generate completion */,
1455
1458
                     icrc, 0 /* generate ICRC */,
1456
 
                     max_statrate, hermon_rate ( av ),
 
1459
                     max_statrate, hermon_rate ( dest ),
1457
1460
                     slr, 0,
1458
1461
                     v15, ( ( qp->ext_qpn == IB_QPN_SMI ) ? 1 : 0 ) );
1459
 
        MLX_FILL_1 ( &wqe->mlx.ctrl, 3, rlid, av->lid );
 
1462
        MLX_FILL_1 ( &wqe->mlx.ctrl, 3, rlid, dest->lid );
1460
1463
        MLX_FILL_1 ( &wqe->mlx.data[0], 0,
1461
1464
                     byte_count, iob_len ( &headers ) );
1462
1465
        MLX_FILL_1 ( &wqe->mlx.data[0], 1, l_key, hermon->lkey );
1479
1482
 *
1480
1483
 * @v ibdev             Infiniband device
1481
1484
 * @v qp                Queue pair
1482
 
 * @v av                Address vector
 
1485
 * @v dest              Destination address vector
1483
1486
 * @v iobuf             I/O buffer
1484
1487
 * @v wqe               Send work queue entry
1485
1488
 * @ret opcode          Control opcode
1487
1490
static unsigned int
1488
1491
hermon_fill_rc_send_wqe ( struct ib_device *ibdev,
1489
1492
                          struct ib_queue_pair *qp __unused,
1490
 
                          struct ib_address_vector *av __unused,
 
1493
                          struct ib_address_vector *dest __unused,
1491
1494
                          struct io_buffer *iobuf,
1492
1495
                          union hermon_send_wqe *wqe ) {
1493
1496
        struct hermon *hermon = ib_get_drvdata ( ibdev );
1509
1512
 *
1510
1513
 * @v ibdev             Infiniband device
1511
1514
 * @v qp                Queue pair
1512
 
 * @v av                Address vector
 
1515
 * @v dest              Destination address vector
1513
1516
 * @v iobuf             I/O buffer
1514
1517
 * @v wqe               Send work queue entry
1515
1518
 * @ret opcode          Control opcode
1517
1520
static unsigned int
1518
1521
hermon_fill_eth_send_wqe ( struct ib_device *ibdev,
1519
1522
                           struct ib_queue_pair *qp __unused,
1520
 
                           struct ib_address_vector *av __unused,
 
1523
                           struct ib_address_vector *dest __unused,
1521
1524
                           struct io_buffer *iobuf,
1522
1525
                           union hermon_send_wqe *wqe ) {
1523
1526
        struct hermon *hermon = ib_get_drvdata ( ibdev );
1542
1545
static unsigned int
1543
1546
( * hermon_fill_send_wqe[] ) ( struct ib_device *ibdev,
1544
1547
                               struct ib_queue_pair *qp,
1545
 
                               struct ib_address_vector *av,
 
1548
                               struct ib_address_vector *dest,
1546
1549
                               struct io_buffer *iobuf,
1547
1550
                               union hermon_send_wqe *wqe ) = {
1548
1551
        [IB_QPT_SMI] = hermon_fill_mlx_send_wqe,
1557
1560
 *
1558
1561
 * @v ibdev             Infiniband device
1559
1562
 * @v qp                Queue pair
1560
 
 * @v av                Address vector
 
1563
 * @v dest              Destination address vector
1561
1564
 * @v iobuf             I/O buffer
1562
1565
 * @ret rc              Return status code
1563
1566
 */
1564
1567
static int hermon_post_send ( struct ib_device *ibdev,
1565
1568
                              struct ib_queue_pair *qp,
1566
 
                              struct ib_address_vector *av,
 
1569
                              struct ib_address_vector *dest,
1567
1570
                              struct io_buffer *iobuf ) {
1568
1571
        struct hermon *hermon = ib_get_drvdata ( ibdev );
1569
1572
        struct hermon_queue_pair *hermon_qp = ib_qp_get_drvdata ( qp );
1594
1597
        assert ( qp->type < ( sizeof ( hermon_fill_send_wqe ) /
1595
1598
                              sizeof ( hermon_fill_send_wqe[0] ) ) );
1596
1599
        assert ( hermon_fill_send_wqe[qp->type] != NULL );
1597
 
        opcode = hermon_fill_send_wqe[qp->type] ( ibdev, qp, av, iobuf, wqe );
 
1600
        opcode = hermon_fill_send_wqe[qp->type] ( ibdev, qp, dest, iobuf, wqe );
1598
1601
        barrier();
1599
1602
        MLX_FILL_2 ( &wqe->ctrl, 0,
1600
1603
                     opcode, opcode,
1676
1679
        struct ib_work_queue *wq;
1677
1680
        struct ib_queue_pair *qp;
1678
1681
        struct io_buffer *iobuf;
1679
 
        struct ib_address_vector recv_av;
 
1682
        struct ib_address_vector recv_dest;
 
1683
        struct ib_address_vector recv_source;
1680
1684
        struct ib_global_route_header *grh;
1681
 
        struct ib_address_vector *av;
 
1685
        struct ib_address_vector *source;
1682
1686
        unsigned int opcode;
1683
1687
        unsigned long qpn;
1684
1688
        int is_send;
1736
1740
                len = MLX_GET ( &cqe->normal, byte_cnt );
1737
1741
                assert ( len <= iob_tailroom ( iobuf ) );
1738
1742
                iob_put ( iobuf, len );
1739
 
                memset ( &recv_av, 0, sizeof ( recv_av ) );
 
1743
                memset ( &recv_dest, 0, sizeof ( recv_dest ) );
 
1744
                recv_dest.qpn = qpn;
 
1745
                memset ( &recv_source, 0, sizeof ( recv_source ) );
1740
1746
                switch ( qp->type ) {
1741
1747
                case IB_QPT_SMI:
1742
1748
                case IB_QPT_GSI:
1745
1751
                        grh = iobuf->data;
1746
1752
                        iob_pull ( iobuf, sizeof ( *grh ) );
1747
1753
                        /* Construct address vector */
1748
 
                        av = &recv_av;
1749
 
                        av->qpn = MLX_GET ( &cqe->normal, srq_rqpn );
1750
 
                        av->lid = MLX_GET ( &cqe->normal, slid_smac47_32 );
1751
 
                        av->sl = MLX_GET ( &cqe->normal, sl );
1752
 
                        av->gid_present = MLX_GET ( &cqe->normal, g );
1753
 
                        memcpy ( &av->gid, &grh->sgid, sizeof ( av->gid ) );
 
1754
                        source = &recv_source;
 
1755
                        source->qpn = MLX_GET ( &cqe->normal, srq_rqpn );
 
1756
                        source->lid = MLX_GET ( &cqe->normal, slid_smac47_32 );
 
1757
                        source->sl = MLX_GET ( &cqe->normal, sl );
 
1758
                        recv_dest.gid_present = source->gid_present =
 
1759
                                MLX_GET ( &cqe->normal, g );
 
1760
                        memcpy ( &recv_dest.gid, &grh->dgid,
 
1761
                                 sizeof ( recv_dest.gid ) );
 
1762
                        memcpy ( &source->gid, &grh->sgid,
 
1763
                                 sizeof ( source->gid ) );
1754
1764
                        break;
1755
1765
                case IB_QPT_RC:
1756
 
                        av = &qp->av;
 
1766
                        source = &qp->av;
1757
1767
                        break;
1758
1768
                case IB_QPT_ETH:
1759
1769
                        /* Construct address vector */
1760
 
                        av = &recv_av;
1761
 
                        av->vlan_present = MLX_GET ( &cqe->normal, vlan );
1762
 
                        av->vlan = MLX_GET ( &cqe->normal, vid );
 
1770
                        source = &recv_source;
 
1771
                        source->vlan_present = MLX_GET ( &cqe->normal, vlan );
 
1772
                        source->vlan = MLX_GET ( &cqe->normal, vid );
1763
1773
                        break;
1764
1774
                default:
1765
1775
                        assert ( 0 );
1766
1776
                        return -EINVAL;
1767
1777
                }
1768
1778
                /* Hand off to completion handler */
1769
 
                ib_complete_recv ( ibdev, qp, av, iobuf, rc );
 
1779
                ib_complete_recv ( ibdev, qp, &recv_dest, source, iobuf, rc );
1770
1780
        }
1771
1781
 
1772
1782
        return rc;
3127
3137
        return 0;
3128
3138
}
3129
3139
 
 
3140
/** Hermon Ethernet queue pair operations */
 
3141
static struct ib_queue_pair_operations hermon_eth_qp_op = {
 
3142
        .alloc_iob = alloc_iob,
 
3143
};
 
3144
 
3130
3145
/**
3131
3146
 * Handle Hermon Ethernet device send completion
3132
3147
 *
3148
3163
 *
3149
3164
 * @v ibdev             Infiniband device
3150
3165
 * @v qp                Queue pair
3151
 
 * @v av                Address vector, or NULL
 
3166
 * @v dest              Destination address vector, or NULL
 
3167
 * @v source            Source address vector, or NULL
3152
3168
 * @v iobuf             I/O buffer
3153
3169
 * @v rc                Completion status code
3154
3170
 */
3155
3171
static void hermon_eth_complete_recv ( struct ib_device *ibdev __unused,
3156
3172
                                       struct ib_queue_pair *qp,
3157
 
                                       struct ib_address_vector *av,
 
3173
                                       struct ib_address_vector *dest __unused,
 
3174
                                       struct ib_address_vector *source,
3158
3175
                                       struct io_buffer *iobuf, int rc ) {
3159
3176
        struct net_device *netdev = ib_qp_get_ownerdata ( qp );
3160
3177
        struct net_device *vlan;
3161
3178
 
3162
3179
        /* Find VLAN device, if applicable */
3163
 
        if ( av->vlan_present ) {
3164
 
                if ( ( vlan = vlan_find ( netdev, av->vlan ) ) != NULL ) {
 
3180
        if ( source->vlan_present ) {
 
3181
                if ( ( vlan = vlan_find ( netdev, source->vlan ) ) != NULL ) {
3165
3182
                        netdev = vlan;
3166
3183
                } else if ( rc == 0 ) {
3167
3184
                        rc = -ENODEV;
3224
3241
        /* Allocate queue pair */
3225
3242
        port->eth_qp = ib_create_qp ( ibdev, IB_QPT_ETH,
3226
3243
                                      HERMON_ETH_NUM_SEND_WQES, port->eth_cq,
3227
 
                                      HERMON_ETH_NUM_RECV_WQES, port->eth_cq );
 
3244
                                      HERMON_ETH_NUM_RECV_WQES, port->eth_cq,
 
3245
                                      &hermon_eth_qp_op );
3228
3246
        if ( ! port->eth_qp ) {
3229
3247
                DBGC ( hermon, "Hermon %p port %d could not create queue "
3230
3248
                       "pair\n", hermon, ibdev->port );
3367
3385
                                            &query_port ) ) != 0 ) {
3368
3386
                DBGC ( hermon, "Hermon %p port %d could not query port: %s\n",
3369
3387
                       hermon, ibdev->port, strerror ( rc ) );
3370
 
                return rc;
 
3388
                goto err_query_port;
3371
3389
        }
3372
3390
        mac.dwords[0] = htonl ( MLX_GET ( &query_port, mac_47_32 ) );
3373
3391
        mac.dwords[1] = htonl ( MLX_GET ( &query_port, mac_31_0 ) );
3378
3396
        if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
3379
3397
                DBGC ( hermon, "Hermon %p port %d could not register network "
3380
3398
                       "device: %s\n", hermon, ibdev->port, strerror ( rc ) );
3381
 
                return rc;
 
3399
                goto err_register_netdev;
 
3400
        }
 
3401
 
 
3402
        /* Register non-volatile options */
 
3403
        if ( ( rc = register_nvo ( &port->nvo,
 
3404
                                   netdev_settings ( netdev ) ) ) != 0 ) {
 
3405
                DBGC ( hermon, "Hermon %p port %d could not register non-"
 
3406
                       "volatile options: %s\n",
 
3407
                       hermon, ibdev->port, strerror ( rc ) );
 
3408
                goto err_register_nvo;
3382
3409
        }
3383
3410
 
3384
3411
        return 0;
 
3412
 
 
3413
        unregister_nvo ( &port->nvo );
 
3414
 err_register_nvo:
 
3415
        unregister_netdev ( netdev );
 
3416
 err_register_netdev:
 
3417
 err_query_port:
 
3418
        return rc;
3385
3419
}
3386
3420
 
3387
3421
/**
3413
3447
                                       struct hermon_port *port ) {
3414
3448
        struct net_device *netdev = port->netdev;
3415
3449
 
 
3450
        unregister_nvo ( &port->nvo );
3416
3451
        unregister_netdev ( netdev );
3417
3452
}
3418
3453
 
3806
3841
                        goto err_set_port_type;
3807
3842
        }
3808
3843
 
 
3844
        /* Initialise non-volatile storage */
 
3845
        nvs_vpd_init ( &hermon->nvsvpd, pci );
 
3846
        for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
 
3847
                port = &hermon->port[i];
 
3848
                nvs_vpd_nvo_init ( &hermon->nvsvpd,
 
3849
                                   HERMON_VPD_FIELD ( port->ibdev->port ),
 
3850
                                   &port->nvo, NULL );
 
3851
        }
 
3852
 
3809
3853
        /* Register devices */
3810
3854
        for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
3811
3855
                port = &hermon->port[i];