aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAlexander Duyck <alexander.h.duyck@intel.com>2009-10-27 11:54:23 -0400
committerDavid S. Miller <davem@davemloft.net>2009-10-28 04:20:37 -0400
commitd7ee5b3a78f57a8ca9ca2392ff5d03f91ec90bdb (patch)
tree3d33ec9251c264370e31a51b084abed238582861 /drivers
parent10d8e9073a320a1c9cc13f996bd600b477eb4872 (diff)
igb: re-use ring configuration code in ethtool testing
Since all of the ring code is now specific to the ring instead of the adapter struct it is possible to cut a large section of code out of the ethtool testing configuraiton since we can just use the existing functions to configure the rings. Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/igb/igb.h14
-rw-r--r--drivers/net/igb/igb_ethtool.c185
-rw-r--r--drivers/net/igb/igb_main.c29
3 files changed, 60 insertions, 168 deletions
diff --git a/drivers/net/igb/igb.h b/drivers/net/igb/igb.h
index 2416c12af3fe..8b189a0c52ef 100644
--- a/drivers/net/igb/igb.h
+++ b/drivers/net/igb/igb.h
@@ -223,6 +223,15 @@ struct igb_ring {
223#define E1000_TX_CTXTDESC_ADV(R, i) \ 223#define E1000_TX_CTXTDESC_ADV(R, i) \
224 (&(((struct e1000_adv_tx_context_desc *)((R).desc))[i])) 224 (&(((struct e1000_adv_tx_context_desc *)((R).desc))[i]))
225 225
226/* igb_desc_unused - calculate if we have unused descriptors */
227static inline int igb_desc_unused(struct igb_ring *ring)
228{
229 if (ring->next_to_clean > ring->next_to_use)
230 return ring->next_to_clean - ring->next_to_use - 1;
231
232 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
233}
234
226/* board specific private data structure */ 235/* board specific private data structure */
227 236
228struct igb_adapter { 237struct igb_adapter {
@@ -336,6 +345,11 @@ extern int igb_setup_tx_resources(struct igb_ring *);
336extern int igb_setup_rx_resources(struct igb_ring *); 345extern int igb_setup_rx_resources(struct igb_ring *);
337extern void igb_free_tx_resources(struct igb_ring *); 346extern void igb_free_tx_resources(struct igb_ring *);
338extern void igb_free_rx_resources(struct igb_ring *); 347extern void igb_free_rx_resources(struct igb_ring *);
348extern void igb_configure_tx_ring(struct igb_adapter *, struct igb_ring *);
349extern void igb_configure_rx_ring(struct igb_adapter *, struct igb_ring *);
350extern void igb_setup_tctl(struct igb_adapter *);
351extern void igb_setup_rctl(struct igb_adapter *);
352extern void igb_alloc_rx_buffers_adv(struct igb_ring *, int);
339extern void igb_update_stats(struct igb_adapter *); 353extern void igb_update_stats(struct igb_adapter *);
340extern void igb_set_ethtool_ops(struct net_device *); 354extern void igb_set_ethtool_ops(struct net_device *);
341 355
diff --git a/drivers/net/igb/igb_ethtool.c b/drivers/net/igb/igb_ethtool.c
index c44dedec1265..80afd8a0b123 100644
--- a/drivers/net/igb/igb_ethtool.c
+++ b/drivers/net/igb/igb_ethtool.c
@@ -1245,116 +1245,49 @@ static int igb_intr_test(struct igb_adapter *adapter, u64 *data)
1245 1245
1246static void igb_free_desc_rings(struct igb_adapter *adapter) 1246static void igb_free_desc_rings(struct igb_adapter *adapter)
1247{ 1247{
1248 struct igb_ring *tx_ring = &adapter->test_tx_ring; 1248 igb_free_tx_resources(&adapter->test_tx_ring);
1249 struct igb_ring *rx_ring = &adapter->test_rx_ring; 1249 igb_free_rx_resources(&adapter->test_rx_ring);
1250 struct pci_dev *pdev = adapter->pdev;
1251 int i;
1252
1253 if (tx_ring->desc && tx_ring->buffer_info) {
1254 for (i = 0; i < tx_ring->count; i++) {
1255 struct igb_buffer *buf = &(tx_ring->buffer_info[i]);
1256 if (buf->dma)
1257 pci_unmap_single(pdev, buf->dma, buf->length,
1258 PCI_DMA_TODEVICE);
1259 if (buf->skb)
1260 dev_kfree_skb(buf->skb);
1261 }
1262 }
1263
1264 if (rx_ring->desc && rx_ring->buffer_info) {
1265 for (i = 0; i < rx_ring->count; i++) {
1266 struct igb_buffer *buf = &(rx_ring->buffer_info[i]);
1267 if (buf->dma)
1268 pci_unmap_single(pdev, buf->dma,
1269 IGB_RXBUFFER_2048,
1270 PCI_DMA_FROMDEVICE);
1271 if (buf->skb)
1272 dev_kfree_skb(buf->skb);
1273 }
1274 }
1275
1276 if (tx_ring->desc) {
1277 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc,
1278 tx_ring->dma);
1279 tx_ring->desc = NULL;
1280 }
1281 if (rx_ring->desc) {
1282 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc,
1283 rx_ring->dma);
1284 rx_ring->desc = NULL;
1285 }
1286
1287 kfree(tx_ring->buffer_info);
1288 tx_ring->buffer_info = NULL;
1289 kfree(rx_ring->buffer_info);
1290 rx_ring->buffer_info = NULL;
1291
1292 return;
1293} 1250}
1294 1251
1295static int igb_setup_desc_rings(struct igb_adapter *adapter) 1252static int igb_setup_desc_rings(struct igb_adapter *adapter)
1296{ 1253{
1297 struct e1000_hw *hw = &adapter->hw;
1298 struct igb_ring *tx_ring = &adapter->test_tx_ring; 1254 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1299 struct igb_ring *rx_ring = &adapter->test_rx_ring; 1255 struct igb_ring *rx_ring = &adapter->test_rx_ring;
1300 struct pci_dev *pdev = adapter->pdev; 1256 struct e1000_hw *hw = &adapter->hw;
1301 struct igb_buffer *buffer_info;
1302 u32 rctl;
1303 int i, ret_val; 1257 int i, ret_val;
1304 1258
1305 /* Setup Tx descriptor ring and Tx buffers */ 1259 /* Setup Tx descriptor ring and Tx buffers */
1260 tx_ring->count = IGB_DEFAULT_TXD;
1261 tx_ring->pdev = adapter->pdev;
1262 tx_ring->netdev = adapter->netdev;
1263 tx_ring->reg_idx = adapter->vfs_allocated_count;
1306 1264
1307 if (!tx_ring->count) 1265 if (igb_setup_tx_resources(tx_ring)) {
1308 tx_ring->count = IGB_DEFAULT_TXD;
1309
1310 tx_ring->buffer_info = kcalloc(tx_ring->count,
1311 sizeof(struct igb_buffer),
1312 GFP_KERNEL);
1313 if (!tx_ring->buffer_info) {
1314 ret_val = 1; 1266 ret_val = 1;
1315 goto err_nomem; 1267 goto err_nomem;
1316 } 1268 }
1317 1269
1318 tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc); 1270 igb_setup_tctl(adapter);
1319 tx_ring->size = ALIGN(tx_ring->size, 4096); 1271 igb_configure_tx_ring(adapter, tx_ring);
1320 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
1321 &tx_ring->dma);
1322 if (!tx_ring->desc) {
1323 ret_val = 2;
1324 goto err_nomem;
1325 }
1326 tx_ring->next_to_use = tx_ring->next_to_clean = 0;
1327
1328 wr32(E1000_TDBAL(0),
1329 ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1330 wr32(E1000_TDBAH(0), ((u64) tx_ring->dma >> 32));
1331 wr32(E1000_TDLEN(0),
1332 tx_ring->count * sizeof(union e1000_adv_tx_desc));
1333 wr32(E1000_TDH(0), 0);
1334 wr32(E1000_TDT(0), 0);
1335 wr32(E1000_TCTL,
1336 E1000_TCTL_PSP | E1000_TCTL_EN |
1337 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1338 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1339 1272
1340 for (i = 0; i < tx_ring->count; i++) { 1273 for (i = 0; i < tx_ring->count; i++) {
1341 union e1000_adv_tx_desc *tx_desc; 1274 union e1000_adv_tx_desc *tx_desc;
1342 struct sk_buff *skb;
1343 unsigned int size = 1024; 1275 unsigned int size = 1024;
1276 struct sk_buff *skb = alloc_skb(size, GFP_KERNEL);
1344 1277
1345 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
1346 skb = alloc_skb(size, GFP_KERNEL);
1347 if (!skb) { 1278 if (!skb) {
1348 ret_val = 3; 1279 ret_val = 2;
1349 goto err_nomem; 1280 goto err_nomem;
1350 } 1281 }
1351 skb_put(skb, size); 1282 skb_put(skb, size);
1352 buffer_info = &tx_ring->buffer_info[i]; 1283 tx_ring->buffer_info[i].skb = skb;
1353 buffer_info->skb = skb; 1284 tx_ring->buffer_info[i].length = skb->len;
1354 buffer_info->length = skb->len; 1285 tx_ring->buffer_info[i].dma =
1355 buffer_info->dma = pci_map_single(pdev, skb->data, skb->len, 1286 pci_map_single(tx_ring->pdev, skb->data, skb->len,
1356 PCI_DMA_TODEVICE); 1287 PCI_DMA_TODEVICE);
1357 tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); 1288 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
1289 tx_desc->read.buffer_addr =
1290 cpu_to_le64(tx_ring->buffer_info[i].dma);
1358 tx_desc->read.olinfo_status = cpu_to_le32(skb->len) << 1291 tx_desc->read.olinfo_status = cpu_to_le32(skb->len) <<
1359 E1000_ADVTXD_PAYLEN_SHIFT; 1292 E1000_ADVTXD_PAYLEN_SHIFT;
1360 tx_desc->read.cmd_type_len = cpu_to_le32(skb->len); 1293 tx_desc->read.cmd_type_len = cpu_to_le32(skb->len);
@@ -1366,62 +1299,25 @@ static int igb_setup_desc_rings(struct igb_adapter *adapter)
1366 } 1299 }
1367 1300
1368 /* Setup Rx descriptor ring and Rx buffers */ 1301 /* Setup Rx descriptor ring and Rx buffers */
1369 1302 rx_ring->count = IGB_DEFAULT_RXD;
1370 if (!rx_ring->count) 1303 rx_ring->pdev = adapter->pdev;
1371 rx_ring->count = IGB_DEFAULT_RXD; 1304 rx_ring->netdev = adapter->netdev;
1372 1305 rx_ring->rx_buffer_len = IGB_RXBUFFER_2048;
1373 rx_ring->buffer_info = kcalloc(rx_ring->count, 1306 rx_ring->reg_idx = adapter->vfs_allocated_count;
1374 sizeof(struct igb_buffer), 1307
1375 GFP_KERNEL); 1308 if (igb_setup_rx_resources(rx_ring)) {
1376 if (!rx_ring->buffer_info) { 1309 ret_val = 3;
1377 ret_val = 4;
1378 goto err_nomem;
1379 }
1380
1381 rx_ring->size = rx_ring->count * sizeof(union e1000_adv_rx_desc);
1382 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size,
1383 &rx_ring->dma);
1384 if (!rx_ring->desc) {
1385 ret_val = 5;
1386 goto err_nomem; 1310 goto err_nomem;
1387 } 1311 }
1388 rx_ring->next_to_use = rx_ring->next_to_clean = 0;
1389 1312
1390 rctl = rd32(E1000_RCTL); 1313 /* set the default queue to queue 0 of PF */
1391 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN); 1314 wr32(E1000_MRQC, adapter->vfs_allocated_count << 3);
1392 wr32(E1000_RDBAL(0),
1393 ((u64) rx_ring->dma & 0xFFFFFFFF));
1394 wr32(E1000_RDBAH(0),
1395 ((u64) rx_ring->dma >> 32));
1396 wr32(E1000_RDLEN(0), rx_ring->size);
1397 wr32(E1000_RDH(0), 0);
1398 wr32(E1000_RDT(0), 0);
1399 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1400 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
1401 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1402 wr32(E1000_RCTL, rctl);
1403 wr32(E1000_SRRCTL(0), E1000_SRRCTL_DESCTYPE_ADV_ONEBUF);
1404 1315
1405 for (i = 0; i < rx_ring->count; i++) { 1316 /* enable receive ring */
1406 union e1000_adv_rx_desc *rx_desc; 1317 igb_setup_rctl(adapter);
1407 struct sk_buff *skb; 1318 igb_configure_rx_ring(adapter, rx_ring);
1408 1319
1409 buffer_info = &rx_ring->buffer_info[i]; 1320 igb_alloc_rx_buffers_adv(rx_ring, igb_desc_unused(rx_ring));
1410 rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
1411 skb = alloc_skb(IGB_RXBUFFER_2048 + NET_IP_ALIGN,
1412 GFP_KERNEL);
1413 if (!skb) {
1414 ret_val = 6;
1415 goto err_nomem;
1416 }
1417 skb_reserve(skb, NET_IP_ALIGN);
1418 buffer_info->skb = skb;
1419 buffer_info->dma = pci_map_single(pdev, skb->data,
1420 IGB_RXBUFFER_2048,
1421 PCI_DMA_FROMDEVICE);
1422 rx_desc->read.pkt_addr = cpu_to_le64(buffer_info->dma);
1423 memset(skb->data, 0x00, skb->len);
1424 }
1425 1321
1426 return 0; 1322 return 0;
1427 1323
@@ -1576,15 +1472,12 @@ static int igb_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1576 1472
1577static int igb_run_loopback_test(struct igb_adapter *adapter) 1473static int igb_run_loopback_test(struct igb_adapter *adapter)
1578{ 1474{
1579 struct e1000_hw *hw = &adapter->hw;
1580 struct igb_ring *tx_ring = &adapter->test_tx_ring; 1475 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1581 struct igb_ring *rx_ring = &adapter->test_rx_ring; 1476 struct igb_ring *rx_ring = &adapter->test_rx_ring;
1582 struct pci_dev *pdev = adapter->pdev; 1477 int i, j, k, l, lc, good_cnt, ret_val = 0;
1583 int i, j, k, l, lc, good_cnt;
1584 int ret_val = 0;
1585 unsigned long time; 1478 unsigned long time;
1586 1479
1587 wr32(E1000_RDT(0), rx_ring->count - 1); 1480 writel(rx_ring->count - 1, rx_ring->tail);
1588 1481
1589 /* Calculate the loop count based on the largest descriptor ring 1482 /* Calculate the loop count based on the largest descriptor ring
1590 * The idea is to wrap the largest ring a number of times using 64 1483 * The idea is to wrap the largest ring a number of times using 64
@@ -1601,7 +1494,7 @@ static int igb_run_loopback_test(struct igb_adapter *adapter)
1601 for (i = 0; i < 64; i++) { /* send the packets */ 1494 for (i = 0; i < 64; i++) { /* send the packets */
1602 igb_create_lbtest_frame(tx_ring->buffer_info[k].skb, 1495 igb_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1603 1024); 1496 1024);
1604 pci_dma_sync_single_for_device(pdev, 1497 pci_dma_sync_single_for_device(tx_ring->pdev,
1605 tx_ring->buffer_info[k].dma, 1498 tx_ring->buffer_info[k].dma,
1606 tx_ring->buffer_info[k].length, 1499 tx_ring->buffer_info[k].length,
1607 PCI_DMA_TODEVICE); 1500 PCI_DMA_TODEVICE);
@@ -1609,12 +1502,12 @@ static int igb_run_loopback_test(struct igb_adapter *adapter)
1609 if (k == tx_ring->count) 1502 if (k == tx_ring->count)
1610 k = 0; 1503 k = 0;
1611 } 1504 }
1612 wr32(E1000_TDT(0), k); 1505 writel(k, tx_ring->tail);
1613 msleep(200); 1506 msleep(200);
1614 time = jiffies; /* set the start time for the receive */ 1507 time = jiffies; /* set the start time for the receive */
1615 good_cnt = 0; 1508 good_cnt = 0;
1616 do { /* receive the sent packets */ 1509 do { /* receive the sent packets */
1617 pci_dma_sync_single_for_cpu(pdev, 1510 pci_dma_sync_single_for_cpu(rx_ring->pdev,
1618 rx_ring->buffer_info[l].dma, 1511 rx_ring->buffer_info[l].dma,
1619 IGB_RXBUFFER_2048, 1512 IGB_RXBUFFER_2048,
1620 PCI_DMA_FROMDEVICE); 1513 PCI_DMA_FROMDEVICE);
diff --git a/drivers/net/igb/igb_main.c b/drivers/net/igb/igb_main.c
index 9dd290cf754a..576a4fac51d1 100644
--- a/drivers/net/igb/igb_main.c
+++ b/drivers/net/igb/igb_main.c
@@ -91,8 +91,6 @@ static int igb_open(struct net_device *);
91static int igb_close(struct net_device *); 91static int igb_close(struct net_device *);
92static void igb_configure_tx(struct igb_adapter *); 92static void igb_configure_tx(struct igb_adapter *);
93static void igb_configure_rx(struct igb_adapter *); 93static void igb_configure_rx(struct igb_adapter *);
94static void igb_setup_tctl(struct igb_adapter *);
95static void igb_setup_rctl(struct igb_adapter *);
96static void igb_clean_all_tx_rings(struct igb_adapter *); 94static void igb_clean_all_tx_rings(struct igb_adapter *);
97static void igb_clean_all_rx_rings(struct igb_adapter *); 95static void igb_clean_all_rx_rings(struct igb_adapter *);
98static void igb_clean_tx_ring(struct igb_ring *); 96static void igb_clean_tx_ring(struct igb_ring *);
@@ -120,7 +118,6 @@ static void igb_setup_dca(struct igb_adapter *);
120static bool igb_clean_tx_irq(struct igb_q_vector *); 118static bool igb_clean_tx_irq(struct igb_q_vector *);
121static int igb_poll(struct napi_struct *, int); 119static int igb_poll(struct napi_struct *, int);
122static bool igb_clean_rx_irq_adv(struct igb_q_vector *, int *, int); 120static bool igb_clean_rx_irq_adv(struct igb_q_vector *, int *, int);
123static void igb_alloc_rx_buffers_adv(struct igb_ring *, int);
124static int igb_ioctl(struct net_device *, struct ifreq *, int cmd); 121static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
125static void igb_tx_timeout(struct net_device *); 122static void igb_tx_timeout(struct net_device *);
126static void igb_reset_task(struct work_struct *); 123static void igb_reset_task(struct work_struct *);
@@ -310,17 +307,6 @@ static char *igb_get_time_str(struct igb_adapter *adapter,
310#endif 307#endif
311 308
312/** 309/**
313 * igb_desc_unused - calculate if we have unused descriptors
314 **/
315static int igb_desc_unused(struct igb_ring *ring)
316{
317 if (ring->next_to_clean > ring->next_to_use)
318 return ring->next_to_clean - ring->next_to_use - 1;
319
320 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
321}
322
323/**
324 * igb_init_module - Driver Registration Routine 310 * igb_init_module - Driver Registration Routine
325 * 311 *
326 * igb_init_module is the first routine called when the driver is 312 * igb_init_module is the first routine called when the driver is
@@ -2087,7 +2073,7 @@ static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
2087 * igb_setup_tctl - configure the transmit control registers 2073 * igb_setup_tctl - configure the transmit control registers
2088 * @adapter: Board private structure 2074 * @adapter: Board private structure
2089 **/ 2075 **/
2090static void igb_setup_tctl(struct igb_adapter *adapter) 2076void igb_setup_tctl(struct igb_adapter *adapter)
2091{ 2077{
2092 struct e1000_hw *hw = &adapter->hw; 2078 struct e1000_hw *hw = &adapter->hw;
2093 u32 tctl; 2079 u32 tctl;
@@ -2116,8 +2102,8 @@ static void igb_setup_tctl(struct igb_adapter *adapter)
2116 * 2102 *
2117 * Configure a transmit ring after a reset. 2103 * Configure a transmit ring after a reset.
2118 **/ 2104 **/
2119static void igb_configure_tx_ring(struct igb_adapter *adapter, 2105void igb_configure_tx_ring(struct igb_adapter *adapter,
2120 struct igb_ring *ring) 2106 struct igb_ring *ring)
2121{ 2107{
2122 struct e1000_hw *hw = &adapter->hw; 2108 struct e1000_hw *hw = &adapter->hw;
2123 u32 txdctl; 2109 u32 txdctl;
@@ -2339,7 +2325,7 @@ static void igb_setup_mrqc(struct igb_adapter *adapter)
2339 * igb_setup_rctl - configure the receive control registers 2325 * igb_setup_rctl - configure the receive control registers
2340 * @adapter: Board private structure 2326 * @adapter: Board private structure
2341 **/ 2327 **/
2342static void igb_setup_rctl(struct igb_adapter *adapter) 2328void igb_setup_rctl(struct igb_adapter *adapter)
2343{ 2329{
2344 struct e1000_hw *hw = &adapter->hw; 2330 struct e1000_hw *hw = &adapter->hw;
2345 u32 rctl; 2331 u32 rctl;
@@ -2423,8 +2409,8 @@ static void igb_rlpml_set(struct igb_adapter *adapter)
2423 * 2409 *
2424 * Configure the Rx unit of the MAC after a reset. 2410 * Configure the Rx unit of the MAC after a reset.
2425 **/ 2411 **/
2426static void igb_configure_rx_ring(struct igb_adapter *adapter, 2412void igb_configure_rx_ring(struct igb_adapter *adapter,
2427 struct igb_ring *ring) 2413 struct igb_ring *ring)
2428{ 2414{
2429 struct e1000_hw *hw = &adapter->hw; 2415 struct e1000_hw *hw = &adapter->hw;
2430 u64 rdba = ring->dma; 2416 u64 rdba = ring->dma;
@@ -5034,8 +5020,7 @@ next_desc:
5034 * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split 5020 * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
5035 * @adapter: address of board private structure 5021 * @adapter: address of board private structure
5036 **/ 5022 **/
5037static void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring, 5023void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring, int cleaned_count)
5038 int cleaned_count)
5039{ 5024{
5040 struct net_device *netdev = rx_ring->netdev; 5025 struct net_device *netdev = rx_ring->netdev;
5041 union e1000_adv_rx_desc *rx_desc; 5026 union e1000_adv_rx_desc *rx_desc;