diff options
author | Veena Parat <Veena.Parat@neterion.com> | 2007-07-23 02:37:14 -0400 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2007-07-30 15:56:04 -0400 |
commit | 491abf2537a01bef52bffc67001f59cce1fd0047 (patch) | |
tree | ca8cff9731bf7808b0a0fb17b17dd78fd297813e /drivers/net | |
parent | eccb8628ab97f5b43e04425e983db1495fc0ef32 (diff) |
S2IO: Checking for the return value of pci map function
- Checking for the return value of pci map function
- Implemented Francois Romieu's comments on eliminating code duplication
using goto
- Implemented Francois Romieu's comments on using a temporary variable for
accessing statistics structure
Signed-off-by: Veena Parat <veena.parat@neterion.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/s2io.c | 77 | ||||
-rw-r--r-- | drivers/net/s2io.h | 5 |
2 files changed, 79 insertions, 3 deletions
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c index 724b44360a47..ce3a6d9b13c8 100644 --- a/drivers/net/s2io.c +++ b/drivers/net/s2io.c | |||
@@ -282,6 +282,7 @@ static char ethtool_driver_stats_keys[][ETH_GSTRING_LEN] = { | |||
282 | ("lro_flush_due_to_max_pkts"), | 282 | ("lro_flush_due_to_max_pkts"), |
283 | ("lro_avg_aggr_pkts"), | 283 | ("lro_avg_aggr_pkts"), |
284 | ("mem_alloc_fail_cnt"), | 284 | ("mem_alloc_fail_cnt"), |
285 | ("pci_map_fail_cnt"), | ||
285 | ("watchdog_timer_cnt"), | 286 | ("watchdog_timer_cnt"), |
286 | ("mem_allocated"), | 287 | ("mem_allocated"), |
287 | ("mem_freed"), | 288 | ("mem_freed"), |
@@ -2271,6 +2272,7 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no) | |||
2271 | u64 Buffer0_ptr = 0, Buffer1_ptr = 0; | 2272 | u64 Buffer0_ptr = 0, Buffer1_ptr = 0; |
2272 | struct RxD1 *rxdp1; | 2273 | struct RxD1 *rxdp1; |
2273 | struct RxD3 *rxdp3; | 2274 | struct RxD3 *rxdp3; |
2275 | struct swStat *stats = &nic->mac_control.stats_info->sw_stat; | ||
2274 | 2276 | ||
2275 | mac_control = &nic->mac_control; | 2277 | mac_control = &nic->mac_control; |
2276 | config = &nic->config; | 2278 | config = &nic->config; |
@@ -2360,6 +2362,11 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no) | |||
2360 | rxdp1->Buffer0_ptr = pci_map_single | 2362 | rxdp1->Buffer0_ptr = pci_map_single |
2361 | (nic->pdev, skb->data, size - NET_IP_ALIGN, | 2363 | (nic->pdev, skb->data, size - NET_IP_ALIGN, |
2362 | PCI_DMA_FROMDEVICE); | 2364 | PCI_DMA_FROMDEVICE); |
2365 | if( (rxdp1->Buffer0_ptr == 0) || | ||
2366 | (rxdp1->Buffer0_ptr == | ||
2367 | DMA_ERROR_CODE)) | ||
2368 | goto pci_map_failed; | ||
2369 | |||
2363 | rxdp->Control_2 = | 2370 | rxdp->Control_2 = |
2364 | SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN); | 2371 | SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN); |
2365 | 2372 | ||
@@ -2395,6 +2402,10 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no) | |||
2395 | pci_dma_sync_single_for_device(nic->pdev, | 2402 | pci_dma_sync_single_for_device(nic->pdev, |
2396 | (dma_addr_t) rxdp3->Buffer0_ptr, | 2403 | (dma_addr_t) rxdp3->Buffer0_ptr, |
2397 | BUF0_LEN, PCI_DMA_FROMDEVICE); | 2404 | BUF0_LEN, PCI_DMA_FROMDEVICE); |
2405 | if( (rxdp3->Buffer0_ptr == 0) || | ||
2406 | (rxdp3->Buffer0_ptr == DMA_ERROR_CODE)) | ||
2407 | goto pci_map_failed; | ||
2408 | |||
2398 | rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN); | 2409 | rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN); |
2399 | if (nic->rxd_mode == RXD_MODE_3B) { | 2410 | if (nic->rxd_mode == RXD_MODE_3B) { |
2400 | /* Two buffer mode */ | 2411 | /* Two buffer mode */ |
@@ -2407,12 +2418,22 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no) | |||
2407 | (nic->pdev, skb->data, dev->mtu + 4, | 2418 | (nic->pdev, skb->data, dev->mtu + 4, |
2408 | PCI_DMA_FROMDEVICE); | 2419 | PCI_DMA_FROMDEVICE); |
2409 | 2420 | ||
2410 | /* Buffer-1 will be dummy buffer. Not used */ | 2421 | if( (rxdp3->Buffer2_ptr == 0) || |
2411 | if (!(rxdp3->Buffer1_ptr)) { | 2422 | (rxdp3->Buffer2_ptr == DMA_ERROR_CODE)) |
2412 | rxdp3->Buffer1_ptr = | 2423 | goto pci_map_failed; |
2424 | |||
2425 | rxdp3->Buffer1_ptr = | ||
2413 | pci_map_single(nic->pdev, | 2426 | pci_map_single(nic->pdev, |
2414 | ba->ba_1, BUF1_LEN, | 2427 | ba->ba_1, BUF1_LEN, |
2415 | PCI_DMA_FROMDEVICE); | 2428 | PCI_DMA_FROMDEVICE); |
2429 | if( (rxdp3->Buffer1_ptr == 0) || | ||
2430 | (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) { | ||
2431 | pci_unmap_single | ||
2432 | (nic->pdev, | ||
2433 | (dma_addr_t)skb->data, | ||
2434 | dev->mtu + 4, | ||
2435 | PCI_DMA_FROMDEVICE); | ||
2436 | goto pci_map_failed; | ||
2416 | } | 2437 | } |
2417 | rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1); | 2438 | rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1); |
2418 | rxdp->Control_2 |= SET_BUFFER2_SIZE_3 | 2439 | rxdp->Control_2 |= SET_BUFFER2_SIZE_3 |
@@ -2451,6 +2472,11 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no) | |||
2451 | } | 2472 | } |
2452 | 2473 | ||
2453 | return SUCCESS; | 2474 | return SUCCESS; |
2475 | pci_map_failed: | ||
2476 | stats->pci_map_fail_cnt++; | ||
2477 | stats->mem_freed += skb->truesize; | ||
2478 | dev_kfree_skb_irq(skb); | ||
2479 | return -ENOMEM; | ||
2454 | } | 2480 | } |
2455 | 2481 | ||
2456 | static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk) | 2482 | static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk) |
@@ -3882,6 +3908,7 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev) | |||
3882 | struct mac_info *mac_control; | 3908 | struct mac_info *mac_control; |
3883 | struct config_param *config; | 3909 | struct config_param *config; |
3884 | int offload_type; | 3910 | int offload_type; |
3911 | struct swStat *stats = &sp->mac_control.stats_info->sw_stat; | ||
3885 | 3912 | ||
3886 | mac_control = &sp->mac_control; | 3913 | mac_control = &sp->mac_control; |
3887 | config = &sp->config; | 3914 | config = &sp->config; |
@@ -3966,11 +3993,18 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev) | |||
3966 | txdp->Buffer_Pointer = pci_map_single(sp->pdev, | 3993 | txdp->Buffer_Pointer = pci_map_single(sp->pdev, |
3967 | sp->ufo_in_band_v, | 3994 | sp->ufo_in_band_v, |
3968 | sizeof(u64), PCI_DMA_TODEVICE); | 3995 | sizeof(u64), PCI_DMA_TODEVICE); |
3996 | if((txdp->Buffer_Pointer == 0) || | ||
3997 | (txdp->Buffer_Pointer == DMA_ERROR_CODE)) | ||
3998 | goto pci_map_failed; | ||
3969 | txdp++; | 3999 | txdp++; |
3970 | } | 4000 | } |
3971 | 4001 | ||
3972 | txdp->Buffer_Pointer = pci_map_single | 4002 | txdp->Buffer_Pointer = pci_map_single |
3973 | (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE); | 4003 | (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE); |
4004 | if((txdp->Buffer_Pointer == 0) || | ||
4005 | (txdp->Buffer_Pointer == DMA_ERROR_CODE)) | ||
4006 | goto pci_map_failed; | ||
4007 | |||
3974 | txdp->Host_Control = (unsigned long) skb; | 4008 | txdp->Host_Control = (unsigned long) skb; |
3975 | txdp->Control_1 |= TXD_BUFFER0_SIZE(frg_len); | 4009 | txdp->Control_1 |= TXD_BUFFER0_SIZE(frg_len); |
3976 | if (offload_type == SKB_GSO_UDP) | 4010 | if (offload_type == SKB_GSO_UDP) |
@@ -4027,6 +4061,13 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev) | |||
4027 | spin_unlock_irqrestore(&sp->tx_lock, flags); | 4061 | spin_unlock_irqrestore(&sp->tx_lock, flags); |
4028 | 4062 | ||
4029 | return 0; | 4063 | return 0; |
4064 | pci_map_failed: | ||
4065 | stats->pci_map_fail_cnt++; | ||
4066 | netif_stop_queue(dev); | ||
4067 | stats->mem_freed += skb->truesize; | ||
4068 | dev_kfree_skb(skb); | ||
4069 | spin_unlock_irqrestore(&sp->tx_lock, flags); | ||
4070 | return 0; | ||
4030 | } | 4071 | } |
4031 | 4072 | ||
4032 | static void | 4073 | static void |
@@ -5769,6 +5810,7 @@ static void s2io_get_ethtool_stats(struct net_device *dev, | |||
5769 | else | 5810 | else |
5770 | tmp_stats[i++] = 0; | 5811 | tmp_stats[i++] = 0; |
5771 | tmp_stats[i++] = stat_info->sw_stat.mem_alloc_fail_cnt; | 5812 | tmp_stats[i++] = stat_info->sw_stat.mem_alloc_fail_cnt; |
5813 | tmp_stats[i++] = stat_info->sw_stat.pci_map_fail_cnt; | ||
5772 | tmp_stats[i++] = stat_info->sw_stat.watchdog_timer_cnt; | 5814 | tmp_stats[i++] = stat_info->sw_stat.watchdog_timer_cnt; |
5773 | tmp_stats[i++] = stat_info->sw_stat.mem_allocated; | 5815 | tmp_stats[i++] = stat_info->sw_stat.mem_allocated; |
5774 | tmp_stats[i++] = stat_info->sw_stat.mem_freed; | 5816 | tmp_stats[i++] = stat_info->sw_stat.mem_freed; |
@@ -6112,6 +6154,7 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp, | |||
6112 | u64 *temp2, int size) | 6154 | u64 *temp2, int size) |
6113 | { | 6155 | { |
6114 | struct net_device *dev = sp->dev; | 6156 | struct net_device *dev = sp->dev; |
6157 | struct swStat *stats = &sp->mac_control.stats_info->sw_stat; | ||
6115 | 6158 | ||
6116 | if ((sp->rxd_mode == RXD_MODE_1) && (rxdp->Host_Control == 0)) { | 6159 | if ((sp->rxd_mode == RXD_MODE_1) && (rxdp->Host_Control == 0)) { |
6117 | struct RxD1 *rxdp1 = (struct RxD1 *)rxdp; | 6160 | struct RxD1 *rxdp1 = (struct RxD1 *)rxdp; |
@@ -6144,6 +6187,10 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp, | |||
6144 | pci_map_single( sp->pdev, (*skb)->data, | 6187 | pci_map_single( sp->pdev, (*skb)->data, |
6145 | size - NET_IP_ALIGN, | 6188 | size - NET_IP_ALIGN, |
6146 | PCI_DMA_FROMDEVICE); | 6189 | PCI_DMA_FROMDEVICE); |
6190 | if( (rxdp1->Buffer0_ptr == 0) || | ||
6191 | (rxdp1->Buffer0_ptr == DMA_ERROR_CODE)) { | ||
6192 | goto memalloc_failed; | ||
6193 | } | ||
6147 | rxdp->Host_Control = (unsigned long) (*skb); | 6194 | rxdp->Host_Control = (unsigned long) (*skb); |
6148 | } | 6195 | } |
6149 | } else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) { | 6196 | } else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) { |
@@ -6169,19 +6216,43 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp, | |||
6169 | pci_map_single(sp->pdev, (*skb)->data, | 6216 | pci_map_single(sp->pdev, (*skb)->data, |
6170 | dev->mtu + 4, | 6217 | dev->mtu + 4, |
6171 | PCI_DMA_FROMDEVICE); | 6218 | PCI_DMA_FROMDEVICE); |
6219 | if( (rxdp3->Buffer2_ptr == 0) || | ||
6220 | (rxdp3->Buffer2_ptr == DMA_ERROR_CODE)) { | ||
6221 | goto memalloc_failed; | ||
6222 | } | ||
6172 | rxdp3->Buffer0_ptr = *temp0 = | 6223 | rxdp3->Buffer0_ptr = *temp0 = |
6173 | pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN, | 6224 | pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN, |
6174 | PCI_DMA_FROMDEVICE); | 6225 | PCI_DMA_FROMDEVICE); |
6226 | if( (rxdp3->Buffer0_ptr == 0) || | ||
6227 | (rxdp3->Buffer0_ptr == DMA_ERROR_CODE)) { | ||
6228 | pci_unmap_single (sp->pdev, | ||
6229 | (dma_addr_t)(*skb)->data, | ||
6230 | dev->mtu + 4, PCI_DMA_FROMDEVICE); | ||
6231 | goto memalloc_failed; | ||
6232 | } | ||
6175 | rxdp->Host_Control = (unsigned long) (*skb); | 6233 | rxdp->Host_Control = (unsigned long) (*skb); |
6176 | 6234 | ||
6177 | /* Buffer-1 will be dummy buffer not used */ | 6235 | /* Buffer-1 will be dummy buffer not used */ |
6178 | rxdp3->Buffer1_ptr = *temp1 = | 6236 | rxdp3->Buffer1_ptr = *temp1 = |
6179 | pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN, | 6237 | pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN, |
6180 | PCI_DMA_FROMDEVICE); | 6238 | PCI_DMA_FROMDEVICE); |
6239 | if( (rxdp3->Buffer1_ptr == 0) || | ||
6240 | (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) { | ||
6241 | pci_unmap_single (sp->pdev, | ||
6242 | (dma_addr_t)(*skb)->data, | ||
6243 | dev->mtu + 4, PCI_DMA_FROMDEVICE); | ||
6244 | goto memalloc_failed; | ||
6245 | } | ||
6181 | } | 6246 | } |
6182 | } | 6247 | } |
6183 | return 0; | 6248 | return 0; |
6249 | memalloc_failed: | ||
6250 | stats->pci_map_fail_cnt++; | ||
6251 | stats->mem_freed += (*skb)->truesize; | ||
6252 | dev_kfree_skb(*skb); | ||
6253 | return -ENOMEM; | ||
6184 | } | 6254 | } |
6255 | |||
6185 | static void set_rxd_buffer_size(struct s2io_nic *sp, struct RxD_t *rxdp, | 6256 | static void set_rxd_buffer_size(struct s2io_nic *sp, struct RxD_t *rxdp, |
6186 | int size) | 6257 | int size) |
6187 | { | 6258 | { |
diff --git a/drivers/net/s2io.h b/drivers/net/s2io.h index aa5428c4368e..92983ee7df8c 100644 --- a/drivers/net/s2io.h +++ b/drivers/net/s2io.h | |||
@@ -74,6 +74,10 @@ static int debug_level = ERR_DBG; | |||
74 | /* DEBUG message print. */ | 74 | /* DEBUG message print. */ |
75 | #define DBG_PRINT(dbg_level, args...) if(!(debug_level<dbg_level)) printk(args) | 75 | #define DBG_PRINT(dbg_level, args...) if(!(debug_level<dbg_level)) printk(args) |
76 | 76 | ||
77 | #ifndef DMA_ERROR_CODE | ||
78 | #define DMA_ERROR_CODE (~(dma_addr_t)0x0) | ||
79 | #endif | ||
80 | |||
77 | /* Protocol assist features of the NIC */ | 81 | /* Protocol assist features of the NIC */ |
78 | #define L3_CKSUM_OK 0xFFFF | 82 | #define L3_CKSUM_OK 0xFFFF |
79 | #define L4_CKSUM_OK 0xFFFF | 83 | #define L4_CKSUM_OK 0xFFFF |
@@ -97,6 +101,7 @@ struct swStat { | |||
97 | unsigned long long num_aggregations; | 101 | unsigned long long num_aggregations; |
98 | /* Other statistics */ | 102 | /* Other statistics */ |
99 | unsigned long long mem_alloc_fail_cnt; | 103 | unsigned long long mem_alloc_fail_cnt; |
104 | unsigned long long pci_map_fail_cnt; | ||
100 | unsigned long long watchdog_timer_cnt; | 105 | unsigned long long watchdog_timer_cnt; |
101 | unsigned long long mem_allocated; | 106 | unsigned long long mem_allocated; |
102 | unsigned long long mem_freed; | 107 | unsigned long long mem_freed; |