~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/net/ixgbe/ixgbe_dcb_82599.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*******************************************************************************
2
2
 
3
3
  Intel 10 Gigabit PCI Express Linux driver
4
 
  Copyright(c) 1999 - 2010 Intel Corporation.
 
4
  Copyright(c) 1999 - 2011 Intel Corporation.
5
5
 
6
6
  This program is free software; you can redistribute it and/or modify it
7
7
  under the terms and conditions of the GNU General Public License,
33
33
/**
34
34
 * ixgbe_dcb_config_packet_buffers_82599 - Configure DCB packet buffers
35
35
 * @hw: pointer to hardware structure
36
 
 * @dcb_config: pointer to ixgbe_dcb_config structure
 
36
 * @rx_pba: method to distribute packet buffer
37
37
 *
38
38
 * Configure packet buffers for DCB mode.
39
39
 */
40
 
static s32 ixgbe_dcb_config_packet_buffers_82599(struct ixgbe_hw *hw,
41
 
                                          struct ixgbe_dcb_config *dcb_config)
 
40
static s32 ixgbe_dcb_config_packet_buffers_82599(struct ixgbe_hw *hw, u8 rx_pba)
42
41
{
43
 
        s32 ret_val = 0;
44
 
        u32 value = IXGBE_RXPBSIZE_64KB;
 
42
        int num_tcs = IXGBE_MAX_PACKET_BUFFERS;
 
43
        u32 rx_pb_size = hw->mac.rx_pb_size << IXGBE_RXPBSIZE_SHIFT;
 
44
        u32 rxpktsize;
 
45
        u32 txpktsize;
 
46
        u32 txpbthresh;
45
47
        u8  i = 0;
46
48
 
47
 
        /* Setup Rx packet buffer sizes */
48
 
        switch (dcb_config->rx_pba_cfg) {
49
 
        case pba_80_48:
50
 
                /* Setup the first four at 80KB */
51
 
                value = IXGBE_RXPBSIZE_80KB;
52
 
                for (; i < 4; i++)
53
 
                        IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), value);
54
 
                /* Setup the last four at 48KB...don't re-init i */
55
 
                value = IXGBE_RXPBSIZE_48KB;
56
 
                /* Fall Through */
57
 
        case pba_equal:
58
 
        default:
59
 
                for (; i < IXGBE_MAX_PACKET_BUFFERS; i++)
60
 
                        IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), value);
61
 
 
62
 
                /* Setup Tx packet buffer sizes */
63
 
                for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) {
64
 
                        IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i),
65
 
                                        IXGBE_TXPBSIZE_20KB);
66
 
                        IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i),
67
 
                                        IXGBE_TXPBTHRESH_DCB);
68
 
                }
69
 
                break;
70
 
        }
71
 
 
72
 
        return ret_val;
 
49
        /*
 
50
         * This really means configure the first half of the TCs
 
51
         * (Traffic Classes) to use 5/8 of the Rx packet buffer
 
52
         * space.  To determine the size of the buffer for each TC,
 
53
         * we are multiplying the average size by 5/4 and applying
 
54
         * it to half of the traffic classes.
 
55
         */
 
56
        if (rx_pba == pba_80_48) {
 
57
                rxpktsize = (rx_pb_size * 5) / (num_tcs * 4);
 
58
                rx_pb_size -= rxpktsize * (num_tcs / 2);
 
59
                for (; i < (num_tcs / 2); i++)
 
60
                        IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
 
61
        }
 
62
 
 
63
        /* Divide the remaining Rx packet buffer evenly among the TCs */
 
64
        rxpktsize = rx_pb_size / (num_tcs - i);
 
65
        for (; i < num_tcs; i++)
 
66
                IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
 
67
 
 
68
        /*
 
69
         * Setup Tx packet buffer and threshold equally for all TCs
 
70
         * TXPBTHRESH register is set in K so divide by 1024 and subtract
 
71
         * 10 since the largest packet we support is just over 9K.
 
72
         */
 
73
        txpktsize = IXGBE_TXPBSIZE_MAX / num_tcs;
 
74
        txpbthresh = (txpktsize / 1024) - IXGBE_TXPKT_SIZE_MAX;
 
75
        for (i = 0; i < num_tcs; i++) {
 
76
                IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
 
77
                IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
 
78
        }
 
79
 
 
80
        /* Clear unused TCs, if any, to zero buffer size*/
 
81
        for (; i < MAX_TRAFFIC_CLASS; i++) {
 
82
                IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
 
83
                IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
 
84
                IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
 
85
        }
 
86
 
 
87
        return 0;
73
88
}
74
89
 
75
90
/**
76
91
 * ixgbe_dcb_config_rx_arbiter_82599 - Config Rx Data arbiter
77
92
 * @hw: pointer to hardware structure
78
 
 * @dcb_config: pointer to ixgbe_dcb_config structure
 
93
 * @refill: refill credits index by traffic class
 
94
 * @max: max credits index by traffic class
 
95
 * @bwg_id: bandwidth grouping indexed by traffic class
 
96
 * @prio_type: priority type indexed by traffic class
79
97
 *
80
98
 * Configure Rx Packet Arbiter and credits for each traffic class.
81
99
 */
82
 
static s32 ixgbe_dcb_config_rx_arbiter_82599(struct ixgbe_hw *hw,
83
 
                                      struct ixgbe_dcb_config *dcb_config)
 
100
s32 ixgbe_dcb_config_rx_arbiter_82599(struct ixgbe_hw *hw,
 
101
                                      u16 *refill,
 
102
                                      u16 *max,
 
103
                                      u8 *bwg_id,
 
104
                                      u8 *prio_type,
 
105
                                      u8 *prio_tc)
84
106
{
85
 
        struct tc_bw_alloc    *p;
86
107
        u32    reg           = 0;
87
108
        u32    credit_refill = 0;
88
109
        u32    credit_max    = 0;
98
119
        /* Map all traffic classes to their UP, 1 to 1 */
99
120
        reg = 0;
100
121
        for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
101
 
                reg |= (i << (i * IXGBE_RTRUP2TC_UP_SHIFT));
 
122
                reg |= (prio_tc[i] << (i * IXGBE_RTRUP2TC_UP_SHIFT));
102
123
        IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
103
124
 
104
125
        /* Configure traffic class credits and priority */
105
126
        for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
106
 
                p = &dcb_config->tc_config[i].path[DCB_RX_CONFIG];
107
 
 
108
 
                credit_refill = p->data_credits_refill;
109
 
                credit_max    = p->data_credits_max;
 
127
                credit_refill = refill[i];
 
128
                credit_max    = max[i];
110
129
                reg = credit_refill | (credit_max << IXGBE_RTRPT4C_MCL_SHIFT);
111
130
 
112
 
                reg |= (u32)(p->bwg_id) << IXGBE_RTRPT4C_BWG_SHIFT;
 
131
                reg |= (u32)(bwg_id[i]) << IXGBE_RTRPT4C_BWG_SHIFT;
113
132
 
114
 
                if (p->prio_type == prio_link)
 
133
                if (prio_type[i] == prio_link)
115
134
                        reg |= IXGBE_RTRPT4C_LSP;
116
135
 
117
136
                IXGBE_WRITE_REG(hw, IXGBE_RTRPT4C(i), reg);
130
149
/**
131
150
 * ixgbe_dcb_config_tx_desc_arbiter_82599 - Config Tx Desc. arbiter
132
151
 * @hw: pointer to hardware structure
133
 
 * @dcb_config: pointer to ixgbe_dcb_config structure
 
152
 * @refill: refill credits index by traffic class
 
153
 * @max: max credits index by traffic class
 
154
 * @bwg_id: bandwidth grouping indexed by traffic class
 
155
 * @prio_type: priority type indexed by traffic class
134
156
 *
135
157
 * Configure Tx Descriptor Arbiter and credits for each traffic class.
136
158
 */
137
 
static s32 ixgbe_dcb_config_tx_desc_arbiter_82599(struct ixgbe_hw *hw,
138
 
                                           struct ixgbe_dcb_config *dcb_config)
 
159
s32 ixgbe_dcb_config_tx_desc_arbiter_82599(struct ixgbe_hw *hw,
 
160
                                           u16 *refill,
 
161
                                           u16 *max,
 
162
                                           u8 *bwg_id,
 
163
                                           u8 *prio_type)
139
164
{
140
 
        struct tc_bw_alloc *p;
141
165
        u32    reg, max_credits;
142
166
        u8     i;
143
167
 
149
173
 
150
174
        /* Configure traffic class credits and priority */
151
175
        for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
152
 
                p = &dcb_config->tc_config[i].path[DCB_TX_CONFIG];
153
 
                max_credits = dcb_config->tc_config[i].desc_credits_max;
 
176
                max_credits = max[i];
154
177
                reg = max_credits << IXGBE_RTTDT2C_MCL_SHIFT;
155
 
                reg |= p->data_credits_refill;
156
 
                reg |= (u32)(p->bwg_id) << IXGBE_RTTDT2C_BWG_SHIFT;
 
178
                reg |= refill[i];
 
179
                reg |= (u32)(bwg_id[i]) << IXGBE_RTTDT2C_BWG_SHIFT;
157
180
 
158
 
                if (p->prio_type == prio_group)
 
181
                if (prio_type[i] == prio_group)
159
182
                        reg |= IXGBE_RTTDT2C_GSP;
160
183
 
161
 
                if (p->prio_type == prio_link)
 
184
                if (prio_type[i] == prio_link)
162
185
                        reg |= IXGBE_RTTDT2C_LSP;
163
186
 
164
187
                IXGBE_WRITE_REG(hw, IXGBE_RTTDT2C(i), reg);
177
200
/**
178
201
 * ixgbe_dcb_config_tx_data_arbiter_82599 - Config Tx Data arbiter
179
202
 * @hw: pointer to hardware structure
180
 
 * @dcb_config: pointer to ixgbe_dcb_config structure
 
203
 * @refill: refill credits index by traffic class
 
204
 * @max: max credits index by traffic class
 
205
 * @bwg_id: bandwidth grouping indexed by traffic class
 
206
 * @prio_type: priority type indexed by traffic class
181
207
 *
182
208
 * Configure Tx Packet Arbiter and credits for each traffic class.
183
209
 */
184
 
static s32 ixgbe_dcb_config_tx_data_arbiter_82599(struct ixgbe_hw *hw,
185
 
                                           struct ixgbe_dcb_config *dcb_config)
 
210
s32 ixgbe_dcb_config_tx_data_arbiter_82599(struct ixgbe_hw *hw,
 
211
                                           u16 *refill,
 
212
                                           u16 *max,
 
213
                                           u8 *bwg_id,
 
214
                                           u8 *prio_type,
 
215
                                           u8 *prio_tc)
186
216
{
187
 
        struct tc_bw_alloc *p;
188
217
        u32 reg;
189
218
        u8 i;
190
219
 
200
229
        /* Map all traffic classes to their UP, 1 to 1 */
201
230
        reg = 0;
202
231
        for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
203
 
                reg |= (i << (i * IXGBE_RTTUP2TC_UP_SHIFT));
 
232
                reg |= (prio_tc[i] << (i * IXGBE_RTTUP2TC_UP_SHIFT));
204
233
        IXGBE_WRITE_REG(hw, IXGBE_RTTUP2TC, reg);
205
234
 
206
235
        /* Configure traffic class credits and priority */
207
236
        for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
208
 
                p = &dcb_config->tc_config[i].path[DCB_TX_CONFIG];
209
 
                reg = p->data_credits_refill;
210
 
                reg |= (u32)(p->data_credits_max) << IXGBE_RTTPT2C_MCL_SHIFT;
211
 
                reg |= (u32)(p->bwg_id) << IXGBE_RTTPT2C_BWG_SHIFT;
 
237
                reg = refill[i];
 
238
                reg |= (u32)(max[i]) << IXGBE_RTTPT2C_MCL_SHIFT;
 
239
                reg |= (u32)(bwg_id[i]) << IXGBE_RTTPT2C_BWG_SHIFT;
212
240
 
213
 
                if (p->prio_type == prio_group)
 
241
                if (prio_type[i] == prio_group)
214
242
                        reg |= IXGBE_RTTPT2C_GSP;
215
243
 
216
 
                if (p->prio_type == prio_link)
 
244
                if (prio_type[i] == prio_link)
217
245
                        reg |= IXGBE_RTTPT2C_LSP;
218
246
 
219
247
                IXGBE_WRITE_REG(hw, IXGBE_RTTPT2C(i), reg);
233
261
/**
234
262
 * ixgbe_dcb_config_pfc_82599 - Configure priority flow control
235
263
 * @hw: pointer to hardware structure
236
 
 * @dcb_config: pointer to ixgbe_dcb_config structure
 
264
 * @pfc_en: enabled pfc bitmask
237
265
 *
238
266
 * Configure Priority Flow Control (PFC) for each traffic class.
239
267
 */
240
 
s32 ixgbe_dcb_config_pfc_82599(struct ixgbe_hw *hw,
241
 
                               struct ixgbe_dcb_config *dcb_config)
 
268
s32 ixgbe_dcb_config_pfc_82599(struct ixgbe_hw *hw, u8 pfc_en)
242
269
{
243
270
        u32 i, reg, rx_pba_size;
244
271
 
245
 
        /* If PFC is disabled globally then fall back to LFC. */
246
 
        if (!dcb_config->pfc_mode_enable) {
247
 
                for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
248
 
                        hw->mac.ops.fc_enable(hw, i);
249
 
                goto out;
250
 
        }
251
 
 
252
272
        /* Configure PFC Tx thresholds per TC */
253
273
        for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
 
274
                int enabled = pfc_en & (1 << i);
254
275
                rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i));
255
276
                rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT;
256
277
 
257
278
                reg = (rx_pba_size - hw->fc.low_water) << 10;
258
279
 
259
 
                if (dcb_config->tc_config[i].dcb_pfc == pfc_enabled_full ||
260
 
                    dcb_config->tc_config[i].dcb_pfc == pfc_enabled_tx)
 
280
                if (enabled)
261
281
                        reg |= IXGBE_FCRTL_XONE;
262
282
                IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), reg);
263
283
 
264
284
                reg = (rx_pba_size - hw->fc.high_water) << 10;
265
 
                if (dcb_config->tc_config[i].dcb_pfc == pfc_enabled_full ||
266
 
                    dcb_config->tc_config[i].dcb_pfc == pfc_enabled_tx)
 
285
                if (enabled)
267
286
                        reg |= IXGBE_FCRTH_FCEN;
268
287
                IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), reg);
269
288
        }
270
289
 
271
 
        /* Configure pause time (2 TCs per register) */
272
 
        reg = hw->fc.pause_time | (hw->fc.pause_time << 16);
273
 
        for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
274
 
                IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
275
 
 
276
 
        /* Configure flow control refresh threshold value */
277
 
        IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
278
 
 
279
 
        /* Enable Transmit PFC */
280
 
        reg = IXGBE_FCCFG_TFCE_PRIORITY;
281
 
        IXGBE_WRITE_REG(hw, IXGBE_FCCFG, reg);
282
 
 
283
 
        /*
284
 
         * Enable Receive PFC
285
 
         * We will always honor XOFF frames we receive when
286
 
         * we are in PFC mode.
287
 
         */
288
 
        reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
289
 
        reg &= ~IXGBE_MFLCN_RFCE;
290
 
        reg |= IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_DPF;
291
 
        IXGBE_WRITE_REG(hw, IXGBE_MFLCN, reg);
292
 
out:
 
290
        if (pfc_en) {
 
291
                /* Configure pause time (2 TCs per register) */
 
292
                reg = hw->fc.pause_time | (hw->fc.pause_time << 16);
 
293
                for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
 
294
                        IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
 
295
 
 
296
                /* Configure flow control refresh threshold value */
 
297
                IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
 
298
 
 
299
 
 
300
                reg = IXGBE_FCCFG_TFCE_PRIORITY;
 
301
                IXGBE_WRITE_REG(hw, IXGBE_FCCFG, reg);
 
302
                /*
 
303
                 * Enable Receive PFC
 
304
                 * 82599 will always honor XOFF frames we receive when
 
305
                 * we are in PFC mode however X540 only honors enabled
 
306
                 * traffic classes.
 
307
                 */
 
308
                reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
 
309
                reg &= ~IXGBE_MFLCN_RFCE;
 
310
                reg |= IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_DPF;
 
311
 
 
312
                if (hw->mac.type == ixgbe_mac_X540)
 
313
                        reg |= pfc_en << IXGBE_MFLCN_RPFCE_SHIFT;
 
314
 
 
315
                IXGBE_WRITE_REG(hw, IXGBE_MFLCN, reg);
 
316
 
 
317
        } else {
 
318
                for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
 
319
                        hw->mac.ops.fc_enable(hw, i);
 
320
        }
 
321
 
293
322
        return 0;
294
323
}
295
324
 
349
378
/**
350
379
 * ixgbe_dcb_config_82599 - Configure general DCB parameters
351
380
 * @hw: pointer to hardware structure
352
 
 * @dcb_config: pointer to ixgbe_dcb_config structure
353
381
 *
354
382
 * Configure general DCB parameters.
355
383
 */
406
434
/**
407
435
 * ixgbe_dcb_hw_config_82599 - Configure and enable DCB
408
436
 * @hw: pointer to hardware structure
409
 
 * @dcb_config: pointer to ixgbe_dcb_config structure
 
437
 * @rx_pba: method to distribute packet buffer
 
438
 * @refill: refill credits index by traffic class
 
439
 * @max: max credits index by traffic class
 
440
 * @bwg_id: bandwidth grouping indexed by traffic class
 
441
 * @prio_type: priority type indexed by traffic class
 
442
 * @pfc_en: enabled pfc bitmask
410
443
 *
411
444
 * Configure dcb settings and enable dcb mode.
412
445
 */
413
446
s32 ixgbe_dcb_hw_config_82599(struct ixgbe_hw *hw,
414
 
                              struct ixgbe_dcb_config *dcb_config)
 
447
                              u8 rx_pba, u8 pfc_en, u16 *refill,
 
448
                              u16 *max, u8 *bwg_id, u8 *prio_type, u8 *prio_tc)
415
449
{
416
 
        ixgbe_dcb_config_packet_buffers_82599(hw, dcb_config);
 
450
        ixgbe_dcb_config_packet_buffers_82599(hw, rx_pba);
417
451
        ixgbe_dcb_config_82599(hw);
418
 
        ixgbe_dcb_config_rx_arbiter_82599(hw, dcb_config);
419
 
        ixgbe_dcb_config_tx_desc_arbiter_82599(hw, dcb_config);
420
 
        ixgbe_dcb_config_tx_data_arbiter_82599(hw, dcb_config);
421
 
        ixgbe_dcb_config_pfc_82599(hw, dcb_config);
 
452
        ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, bwg_id,
 
453
                                          prio_type, prio_tc);
 
454
        ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max,
 
455
                                               bwg_id, prio_type);
 
456
        ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max,
 
457
                                               bwg_id, prio_type, prio_tc);
 
458
        ixgbe_dcb_config_pfc_82599(hw, pfc_en);
422
459
        ixgbe_dcb_config_tc_stats_82599(hw);
423
460
 
424
461
        return 0;