aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/core/dev.c')
-rw-r--r--net/core/dev.c156
1 files changed, 63 insertions, 93 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index 0b88eba97dab..b624fe4d9bd7 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1140,9 +1140,6 @@ static int __dev_open(struct net_device *dev)
1140 1140
1141 ASSERT_RTNL(); 1141 ASSERT_RTNL();
1142 1142
1143 /*
1144 * Is it even present?
1145 */
1146 if (!netif_device_present(dev)) 1143 if (!netif_device_present(dev))
1147 return -ENODEV; 1144 return -ENODEV;
1148 1145
@@ -1151,9 +1148,6 @@ static int __dev_open(struct net_device *dev)
1151 if (ret) 1148 if (ret)
1152 return ret; 1149 return ret;
1153 1150
1154 /*
1155 * Call device private open method
1156 */
1157 set_bit(__LINK_STATE_START, &dev->state); 1151 set_bit(__LINK_STATE_START, &dev->state);
1158 1152
1159 if (ops->ndo_validate_addr) 1153 if (ops->ndo_validate_addr)
@@ -1162,31 +1156,12 @@ static int __dev_open(struct net_device *dev)
1162 if (!ret && ops->ndo_open) 1156 if (!ret && ops->ndo_open)
1163 ret = ops->ndo_open(dev); 1157 ret = ops->ndo_open(dev);
1164 1158
1165 /*
1166 * If it went open OK then:
1167 */
1168
1169 if (ret) 1159 if (ret)
1170 clear_bit(__LINK_STATE_START, &dev->state); 1160 clear_bit(__LINK_STATE_START, &dev->state);
1171 else { 1161 else {
1172 /*
1173 * Set the flags.
1174 */
1175 dev->flags |= IFF_UP; 1162 dev->flags |= IFF_UP;
1176
1177 /*
1178 * Enable NET_DMA
1179 */
1180 net_dmaengine_get(); 1163 net_dmaengine_get();
1181
1182 /*
1183 * Initialize multicasting status
1184 */
1185 dev_set_rx_mode(dev); 1164 dev_set_rx_mode(dev);
1186
1187 /*
1188 * Wakeup transmit queue engine
1189 */
1190 dev_activate(dev); 1165 dev_activate(dev);
1191 } 1166 }
1192 1167
@@ -1209,22 +1184,13 @@ int dev_open(struct net_device *dev)
1209{ 1184{
1210 int ret; 1185 int ret;
1211 1186
1212 /*
1213 * Is it already up?
1214 */
1215 if (dev->flags & IFF_UP) 1187 if (dev->flags & IFF_UP)
1216 return 0; 1188 return 0;
1217 1189
1218 /*
1219 * Open device
1220 */
1221 ret = __dev_open(dev); 1190 ret = __dev_open(dev);
1222 if (ret < 0) 1191 if (ret < 0)
1223 return ret; 1192 return ret;
1224 1193
1225 /*
1226 * ... and announce new interface.
1227 */
1228 rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING); 1194 rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING);
1229 call_netdevice_notifiers(NETDEV_UP, dev); 1195 call_netdevice_notifiers(NETDEV_UP, dev);
1230 1196
@@ -1240,10 +1206,6 @@ static int __dev_close_many(struct list_head *head)
1240 might_sleep(); 1206 might_sleep();
1241 1207
1242 list_for_each_entry(dev, head, unreg_list) { 1208 list_for_each_entry(dev, head, unreg_list) {
1243 /*
1244 * Tell people we are going down, so that they can
1245 * prepare to death, when device is still operating.
1246 */
1247 call_netdevice_notifiers(NETDEV_GOING_DOWN, dev); 1209 call_netdevice_notifiers(NETDEV_GOING_DOWN, dev);
1248 1210
1249 clear_bit(__LINK_STATE_START, &dev->state); 1211 clear_bit(__LINK_STATE_START, &dev->state);
@@ -1272,15 +1234,7 @@ static int __dev_close_many(struct list_head *head)
1272 if (ops->ndo_stop) 1234 if (ops->ndo_stop)
1273 ops->ndo_stop(dev); 1235 ops->ndo_stop(dev);
1274 1236
1275 /*
1276 * Device is now down.
1277 */
1278
1279 dev->flags &= ~IFF_UP; 1237 dev->flags &= ~IFF_UP;
1280
1281 /*
1282 * Shutdown NET_DMA
1283 */
1284 net_dmaengine_put(); 1238 net_dmaengine_put();
1285 } 1239 }
1286 1240
@@ -1309,9 +1263,6 @@ static int dev_close_many(struct list_head *head)
1309 1263
1310 __dev_close_many(head); 1264 __dev_close_many(head);
1311 1265
1312 /*
1313 * Tell people we are down
1314 */
1315 list_for_each_entry(dev, head, unreg_list) { 1266 list_for_each_entry(dev, head, unreg_list) {
1316 rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING); 1267 rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING);
1317 call_netdevice_notifiers(NETDEV_DOWN, dev); 1268 call_netdevice_notifiers(NETDEV_DOWN, dev);
@@ -1333,11 +1284,13 @@ static int dev_close_many(struct list_head *head)
1333 */ 1284 */
1334int dev_close(struct net_device *dev) 1285int dev_close(struct net_device *dev)
1335{ 1286{
1336 LIST_HEAD(single); 1287 if (dev->flags & IFF_UP) {
1288 LIST_HEAD(single);
1337 1289
1338 list_add(&dev->unreg_list, &single); 1290 list_add(&dev->unreg_list, &single);
1339 dev_close_many(&single); 1291 dev_close_many(&single);
1340 list_del(&single); 1292 list_del(&single);
1293 }
1341 return 0; 1294 return 0;
1342} 1295}
1343EXPORT_SYMBOL(dev_close); 1296EXPORT_SYMBOL(dev_close);
@@ -1353,14 +1306,17 @@ EXPORT_SYMBOL(dev_close);
1353 */ 1306 */
1354void dev_disable_lro(struct net_device *dev) 1307void dev_disable_lro(struct net_device *dev)
1355{ 1308{
1356 if (dev->ethtool_ops && dev->ethtool_ops->get_flags && 1309 u32 flags;
1357 dev->ethtool_ops->set_flags) { 1310
1358 u32 flags = dev->ethtool_ops->get_flags(dev); 1311 if (dev->ethtool_ops && dev->ethtool_ops->get_flags)
1359 if (flags & ETH_FLAG_LRO) { 1312 flags = dev->ethtool_ops->get_flags(dev);
1360 flags &= ~ETH_FLAG_LRO; 1313 else
1361 dev->ethtool_ops->set_flags(dev, flags); 1314 flags = ethtool_op_get_flags(dev);
1362 } 1315
1363 } 1316 if (!(flags & ETH_FLAG_LRO))
1317 return;
1318
1319 __ethtool_set_flags(dev, flags & ~ETH_FLAG_LRO);
1364 WARN_ON(dev->features & NETIF_F_LRO); 1320 WARN_ON(dev->features & NETIF_F_LRO);
1365} 1321}
1366EXPORT_SYMBOL(dev_disable_lro); 1322EXPORT_SYMBOL(dev_disable_lro);
@@ -1368,11 +1324,6 @@ EXPORT_SYMBOL(dev_disable_lro);
1368 1324
1369static int dev_boot_phase = 1; 1325static int dev_boot_phase = 1;
1370 1326
1371/*
1372 * Device change register/unregister. These are not inline or static
1373 * as we export them to the world.
1374 */
1375
1376/** 1327/**
1377 * register_netdevice_notifier - register a network notifier block 1328 * register_netdevice_notifier - register a network notifier block
1378 * @nb: notifier 1329 * @nb: notifier
@@ -1474,6 +1425,7 @@ int call_netdevice_notifiers(unsigned long val, struct net_device *dev)
1474 ASSERT_RTNL(); 1425 ASSERT_RTNL();
1475 return raw_notifier_call_chain(&netdev_chain, val, dev); 1426 return raw_notifier_call_chain(&netdev_chain, val, dev);
1476} 1427}
1428EXPORT_SYMBOL(call_netdevice_notifiers);
1477 1429
1478/* When > 0 there are consumers of rx skb time stamps */ 1430/* When > 0 there are consumers of rx skb time stamps */
1479static atomic_t netstamp_needed = ATOMIC_INIT(0); 1431static atomic_t netstamp_needed = ATOMIC_INIT(0);
@@ -1504,6 +1456,27 @@ static inline void net_timestamp_check(struct sk_buff *skb)
1504 __net_timestamp(skb); 1456 __net_timestamp(skb);
1505} 1457}
1506 1458
1459static inline bool is_skb_forwardable(struct net_device *dev,
1460 struct sk_buff *skb)
1461{
1462 unsigned int len;
1463
1464 if (!(dev->flags & IFF_UP))
1465 return false;
1466
1467 len = dev->mtu + dev->hard_header_len + VLAN_HLEN;
1468 if (skb->len <= len)
1469 return true;
1470
1471 /* if TSO is enabled, we don't care about the length as the packet
1472 * could be forwarded without being segmented before
1473 */
1474 if (skb_is_gso(skb))
1475 return true;
1476
1477 return false;
1478}
1479
1507/** 1480/**
1508 * dev_forward_skb - loopback an skb to another netif 1481 * dev_forward_skb - loopback an skb to another netif
1509 * 1482 *
@@ -1527,8 +1500,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
1527 skb_orphan(skb); 1500 skb_orphan(skb);
1528 nf_reset(skb); 1501 nf_reset(skb);
1529 1502
1530 if (unlikely(!(dev->flags & IFF_UP) || 1503 if (unlikely(!is_skb_forwardable(dev, skb))) {
1531 (skb->len > (dev->mtu + dev->hard_header_len + VLAN_HLEN)))) {
1532 atomic_long_inc(&dev->rx_dropped); 1504 atomic_long_inc(&dev->rx_dropped);
1533 kfree_skb(skb); 1505 kfree_skb(skb);
1534 return NET_RX_DROP; 1506 return NET_RX_DROP;
@@ -2121,7 +2093,7 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
2121 u32 features; 2093 u32 features;
2122 2094
2123 /* 2095 /*
2124 * If device doesnt need skb->dst, release it right now while 2096 * If device doesn't need skb->dst, release it right now while
2125 * its hot in this cpu cache 2097 * its hot in this cpu cache
2126 */ 2098 */
2127 if (dev->priv_flags & IFF_XMIT_DST_RELEASE) 2099 if (dev->priv_flags & IFF_XMIT_DST_RELEASE)
@@ -2181,7 +2153,7 @@ gso:
2181 nskb->next = NULL; 2153 nskb->next = NULL;
2182 2154
2183 /* 2155 /*
2184 * If device doesnt need nskb->dst, release it right now while 2156 * If device doesn't need nskb->dst, release it right now while
2185 * its hot in this cpu cache 2157 * its hot in this cpu cache
2186 */ 2158 */
2187 if (dev->priv_flags & IFF_XMIT_DST_RELEASE) 2159 if (dev->priv_flags & IFF_XMIT_DST_RELEASE)
@@ -3000,8 +2972,8 @@ EXPORT_SYMBOL_GPL(br_fdb_test_addr_hook);
3000 * when CONFIG_NET_CLS_ACT is? otherwise some useless instructions 2972 * when CONFIG_NET_CLS_ACT is? otherwise some useless instructions
3001 * a compare and 2 stores extra right now if we dont have it on 2973 * a compare and 2 stores extra right now if we dont have it on
3002 * but have CONFIG_NET_CLS_ACT 2974 * but have CONFIG_NET_CLS_ACT
3003 * NOTE: This doesnt stop any functionality; if you dont have 2975 * NOTE: This doesn't stop any functionality; if you dont have
3004 * the ingress scheduler, you just cant add policies on ingress. 2976 * the ingress scheduler, you just can't add policies on ingress.
3005 * 2977 *
3006 */ 2978 */
3007static int ing_filter(struct sk_buff *skb, struct netdev_queue *rxq) 2979static int ing_filter(struct sk_buff *skb, struct netdev_queue *rxq)
@@ -3830,7 +3802,7 @@ static void net_rx_action(struct softirq_action *h)
3830 * with netpoll's poll_napi(). Only the entity which 3802 * with netpoll's poll_napi(). Only the entity which
3831 * obtains the lock and sees NAPI_STATE_SCHED set will 3803 * obtains the lock and sees NAPI_STATE_SCHED set will
3832 * actually make the ->poll() call. Therefore we avoid 3804 * actually make the ->poll() call. Therefore we avoid
3833 * accidently calling ->poll() when NAPI is not scheduled. 3805 * accidentally calling ->poll() when NAPI is not scheduled.
3834 */ 3806 */
3835 work = 0; 3807 work = 0;
3836 if (test_bit(NAPI_STATE_SCHED, &n->state)) { 3808 if (test_bit(NAPI_STATE_SCHED, &n->state)) {
@@ -4803,7 +4775,7 @@ static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cm
4803 * is never reached 4775 * is never reached
4804 */ 4776 */
4805 WARN_ON(1); 4777 WARN_ON(1);
4806 err = -EINVAL; 4778 err = -ENOTTY;
4807 break; 4779 break;
4808 4780
4809 } 4781 }
@@ -5071,7 +5043,7 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
5071 /* Set the per device memory buffer space. 5043 /* Set the per device memory buffer space.
5072 * Not applicable in our case */ 5044 * Not applicable in our case */
5073 case SIOCSIFLINK: 5045 case SIOCSIFLINK:
5074 return -EINVAL; 5046 return -ENOTTY;
5075 5047
5076 /* 5048 /*
5077 * Unknown or private ioctl. 5049 * Unknown or private ioctl.
@@ -5092,7 +5064,7 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
5092 /* Take care of Wireless Extensions */ 5064 /* Take care of Wireless Extensions */
5093 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) 5065 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST)
5094 return wext_handle_ioctl(net, &ifr, cmd, arg); 5066 return wext_handle_ioctl(net, &ifr, cmd, arg);
5095 return -EINVAL; 5067 return -ENOTTY;
5096 } 5068 }
5097} 5069}
5098 5070
@@ -5214,33 +5186,37 @@ u32 netdev_fix_features(struct net_device *dev, u32 features)
5214 /* Fix illegal checksum combinations */ 5186 /* Fix illegal checksum combinations */
5215 if ((features & NETIF_F_HW_CSUM) && 5187 if ((features & NETIF_F_HW_CSUM) &&
5216 (features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) { 5188 (features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) {
5217 netdev_info(dev, "mixed HW and IP checksum settings.\n"); 5189 netdev_warn(dev, "mixed HW and IP checksum settings.\n");
5218 features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM); 5190 features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM);
5219 } 5191 }
5220 5192
5221 if ((features & NETIF_F_NO_CSUM) && 5193 if ((features & NETIF_F_NO_CSUM) &&
5222 (features & (NETIF_F_HW_CSUM|NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) { 5194 (features & (NETIF_F_HW_CSUM|NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) {
5223 netdev_info(dev, "mixed no checksumming and other settings.\n"); 5195 netdev_warn(dev, "mixed no checksumming and other settings.\n");
5224 features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM|NETIF_F_HW_CSUM); 5196 features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM|NETIF_F_HW_CSUM);
5225 } 5197 }
5226 5198
5227 /* Fix illegal SG+CSUM combinations. */ 5199 /* Fix illegal SG+CSUM combinations. */
5228 if ((features & NETIF_F_SG) && 5200 if ((features & NETIF_F_SG) &&
5229 !(features & NETIF_F_ALL_CSUM)) { 5201 !(features & NETIF_F_ALL_CSUM)) {
5230 netdev_info(dev, 5202 netdev_dbg(dev,
5231 "Dropping NETIF_F_SG since no checksum feature.\n"); 5203 "Dropping NETIF_F_SG since no checksum feature.\n");
5232 features &= ~NETIF_F_SG; 5204 features &= ~NETIF_F_SG;
5233 } 5205 }
5234 5206
5235 /* TSO requires that SG is present as well. */ 5207 /* TSO requires that SG is present as well. */
5236 if ((features & NETIF_F_TSO) && !(features & NETIF_F_SG)) { 5208 if ((features & NETIF_F_ALL_TSO) && !(features & NETIF_F_SG)) {
5237 netdev_info(dev, "Dropping NETIF_F_TSO since no SG feature.\n"); 5209 netdev_dbg(dev, "Dropping TSO features since no SG feature.\n");
5238 features &= ~NETIF_F_TSO; 5210 features &= ~NETIF_F_ALL_TSO;
5239 } 5211 }
5240 5212
5213 /* TSO ECN requires that TSO is present as well. */
5214 if ((features & NETIF_F_ALL_TSO) == NETIF_F_TSO_ECN)
5215 features &= ~NETIF_F_TSO_ECN;
5216
5241 /* Software GSO depends on SG. */ 5217 /* Software GSO depends on SG. */
5242 if ((features & NETIF_F_GSO) && !(features & NETIF_F_SG)) { 5218 if ((features & NETIF_F_GSO) && !(features & NETIF_F_SG)) {
5243 netdev_info(dev, "Dropping NETIF_F_GSO since no SG feature.\n"); 5219 netdev_dbg(dev, "Dropping NETIF_F_GSO since no SG feature.\n");
5244 features &= ~NETIF_F_GSO; 5220 features &= ~NETIF_F_GSO;
5245 } 5221 }
5246 5222
@@ -5250,13 +5226,13 @@ u32 netdev_fix_features(struct net_device *dev, u32 features)
5250 if (!((features & NETIF_F_GEN_CSUM) || 5226 if (!((features & NETIF_F_GEN_CSUM) ||
5251 (features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)) 5227 (features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))
5252 == (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) { 5228 == (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) {
5253 netdev_info(dev, 5229 netdev_dbg(dev,
5254 "Dropping NETIF_F_UFO since no checksum offload features.\n"); 5230 "Dropping NETIF_F_UFO since no checksum offload features.\n");
5255 features &= ~NETIF_F_UFO; 5231 features &= ~NETIF_F_UFO;
5256 } 5232 }
5257 5233
5258 if (!(features & NETIF_F_SG)) { 5234 if (!(features & NETIF_F_SG)) {
5259 netdev_info(dev, 5235 netdev_dbg(dev,
5260 "Dropping NETIF_F_UFO since no NETIF_F_SG feature.\n"); 5236 "Dropping NETIF_F_UFO since no NETIF_F_SG feature.\n");
5261 features &= ~NETIF_F_UFO; 5237 features &= ~NETIF_F_UFO;
5262 } 5238 }
@@ -5438,12 +5414,6 @@ int register_netdevice(struct net_device *dev)
5438 dev->features |= NETIF_F_SOFT_FEATURES; 5414 dev->features |= NETIF_F_SOFT_FEATURES;
5439 dev->wanted_features = dev->features & dev->hw_features; 5415 dev->wanted_features = dev->features & dev->hw_features;
5440 5416
5441 /* Avoid warning from netdev_fix_features() for GSO without SG */
5442 if (!(dev->wanted_features & NETIF_F_SG)) {
5443 dev->wanted_features &= ~NETIF_F_GSO;
5444 dev->features &= ~NETIF_F_GSO;
5445 }
5446
5447 /* Enable GRO and NETIF_F_HIGHDMA for vlans by default, 5417 /* Enable GRO and NETIF_F_HIGHDMA for vlans by default,
5448 * vlan_dev_init() will do the dev->features check, so these features 5418 * vlan_dev_init() will do the dev->features check, so these features
5449 * are enabled only if supported by underlying device. 5419 * are enabled only if supported by underlying device.
@@ -6366,7 +6336,7 @@ static void __net_exit default_device_exit(struct net *net)
6366 if (dev->rtnl_link_ops) 6336 if (dev->rtnl_link_ops)
6367 continue; 6337 continue;
6368 6338
6369 /* Push remaing network devices to init_net */ 6339 /* Push remaining network devices to init_net */
6370 snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex); 6340 snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
6371 err = dev_change_net_namespace(dev, &init_net, fb_name); 6341 err = dev_change_net_namespace(dev, &init_net, fb_name);
6372 if (err) { 6342 if (err) {