9 #define KMSG_COMPONENT "qeth"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/module.h>
14 #include <linux/bitops.h>
15 #include <linux/string.h>
16 #include <linux/errno.h>
17 #include <linux/kernel.h>
19 #include <linux/mii.h>
21 #include <linux/ipv6.h>
23 #include <linux/igmp.h>
24 #include <linux/slab.h>
25 #include <linux/if_vlan.h>
38 static int qeth_l3_recover(
void *);
40 static void qeth_l3_set_multicast_list(
struct net_device *);
42 static int qeth_l3_register_addr_entry(
struct qeth_card *,
44 static int qeth_l3_deregister_addr_entry(
struct qeth_card *,
49 static int qeth_l3_isxdigit(
char *
buf)
60 sprintf(buf,
"%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
70 &in[0], &in[1], &in[2], &in[3], &c);
71 if (
rc != 4 && (
rc != 5 || c !=
'\n'))
73 for (count = 0; count < 4; count++) {
92 unsigned short in_tmp[8] = {0, };
94 cnt = out = found = save_cnt = num2 = 0;
102 end_tmp =
strchr(start,
'\n');
109 if ((end - start) > 4)
111 memcpy(num, start, end - start);
112 if (!qeth_l3_isxdigit(num))
114 sscanf(start,
"%x", &num2);
116 in_tmp[save_cnt++] =
num2;
128 if (cnt + save_cnt > 8)
132 in[cnt--] = in_tmp[--save_cnt];
156 static void qeth_l3_convert_addr_to_bits(
u8 *
addr,
u8 *
bits,
int len)
161 for (i = 0; i < len; ++
i) {
163 for (j = 7; j >= 0; --
j) {
164 bits[i*8 +
j] = octet & 1;
174 u8 addr_bits[128] = {0, };
175 u8 ipatoe_bits[128] = {0, };
178 if (!card->
ipato.enabled)
181 qeth_l3_convert_addr_to_bits((
u8 *) &addr->
u, addr_bits,
186 qeth_l3_convert_addr_to_bits(ipatoe->
addr, ipatoe_bits,
190 rc = !
memcmp(addr_bits, ipatoe_bits,
193 rc = !
memcmp(addr_bits, ipatoe_bits,
228 (tmp->
u.
a4.addr == addr->
u.
a4.addr) &&
229 (tmp->
u.
a4.mask == addr->
u.
a4.mask)) {
237 (tmp->
u.
a6.pfxlen == addr->
u.
a6.pfxlen) &&
245 if (addr->
users != 0)
248 tmp->
users += add ? 1 : -1;
249 if (tmp->
users == 0) {
258 if (addr->
users == 0)
259 addr->
users += add ? 1 : -1;
285 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
286 spin_unlock_irqrestore(&card->
ip_lock, flags);
303 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
304 spin_unlock_irqrestore(&card->
ip_lock, flags);
323 static void qeth_l3_delete_mc_addresses(
struct qeth_card *card)
336 if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
338 spin_unlock_irqrestore(&card->
ip_lock, flags);
354 static int __qeth_l3_ref_ip_on_card(
struct qeth_card *card,
364 (addr->
u.
a4.addr == todo->
u.
a4.addr) &&
365 (addr->
u.
a4.mask == todo->
u.
a4.mask)) {
372 (addr->
u.
a6.pfxlen == todo->
u.
a6.pfxlen) &&
381 if (addr->
users <= 0) {
391 if (todo->
users > 0) {
400 static void __qeth_l3_delete_all_mc(
struct qeth_card *card,
401 unsigned long *flags)
407 INIT_LIST_HEAD(&fail_list);
412 spin_unlock_irqrestore(&card->
ip_lock, *flags);
413 rc = qeth_l3_deregister_addr_entry(card, addr);
422 list_splice(&fail_list, &card->
ip_list);
446 spin_unlock_irqrestore(&card->
ip_lock, flags);
451 while (!list_empty(tbd_list)) {
455 __qeth_l3_delete_all_mc(card, &flags);
459 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
463 }
else if (rc == 1) {
465 spin_unlock_irqrestore(&card->
ip_lock, flags);
466 rc = qeth_l3_register_addr_entry(card, todo);
472 }
else if (rc == -1) {
474 list_del_init(&addr->
entry);
475 spin_unlock_irqrestore(&card->
ip_lock, flags);
476 rc = qeth_l3_deregister_addr_entry(card, addr);
485 spin_unlock_irqrestore(&card->
ip_lock, flags);
489 static void qeth_l3_clear_ip_list(
struct qeth_card *card,
int recover)
495 if (recover && card->
options.sniffer)
504 while (!list_empty(&card->
ip_list)) {
507 list_del_init(&addr->
entry);
514 spin_unlock_irqrestore(&card->
ip_lock, flags);
517 static int qeth_l3_address_exists_in_list(
struct list_head *
list,
525 ((same_type && (tmp->
type == addr->
type)) ||
526 (!same_type && (tmp->
type != addr->
type))) &&
527 (tmp->
u.
a4.addr == addr->
u.
a4.addr))
532 ((same_type && (tmp->
type == addr->
type)) ||
533 (!same_type && (tmp->
type != addr->
type))) &&
542 static int qeth_l3_send_setdelmc(
struct qeth_card *card,
565 static void qeth_l3_fill_netmask(
u8 *netmask,
unsigned int len)
568 for (i = 0; i < 16; i++) {
573 netmask[
i] = (
u8)(0xFF00 >> j);
579 static int qeth_l3_send_setdelip(
struct qeth_card *card,
580 struct qeth_ipaddr *addr,
int ipacmd,
unsigned int flags)
595 qeth_l3_fill_netmask(netmask, addr->
u.
a6.pfxlen);
610 static int qeth_l3_send_setrouting(
struct qeth_card *card,
626 static void qeth_l3_correct_routing_type(
struct qeth_card *card,
663 qeth_l3_correct_routing_type(card, &card->
options.route4.type,
666 rc = qeth_l3_send_setrouting(card, card->
options.route4.type,
671 " on %s. Type set to 'no router'.\n", rc,
682 #ifdef CONFIG_QETH_IPV6
686 qeth_l3_correct_routing_type(card, &card->
options.route6.type,
689 rc = qeth_l3_send_setrouting(card, card->
options.route6.type,
694 " on %s. Type set to 'no router'.\n", rc,
704 static void qeth_l3_clear_ipato_list(
struct qeth_card *card)
715 spin_unlock_irqrestore(&card->
ip_lock, flags);
728 if (ipatoe->
proto != new->proto)
740 spin_unlock_irqrestore(&card->
ip_lock, flags);
753 if (ipatoe->
proto != proto)
762 spin_unlock_irqrestore(&card->
ip_lock, flags);
780 ipaddr->
u.
a4.mask = 0;
784 ipaddr->
u.
a6.pfxlen = 0;
792 if (qeth_l3_address_exists_in_list(&card->
ip_list, ipaddr, 0) ||
793 qeth_l3_address_exists_in_list(card->
ip_tbd_list, ipaddr, 0))
795 spin_unlock_irqrestore(&card->
ip_lock, flags);
816 ipaddr->
u.
a4.mask = 0;
820 ipaddr->
u.
a6.pfxlen = 0;
845 ipaddr->
u.
a4.mask = 0;
849 ipaddr->
u.
a6.pfxlen = 0;
857 if (qeth_l3_address_exists_in_list(&card->
ip_list, ipaddr, 0) ||
858 qeth_l3_address_exists_in_list(card->
ip_tbd_list, ipaddr, 0))
860 spin_unlock_irqrestore(&card->
ip_lock, flags);
881 ipaddr->
u.
a4.mask = 0;
885 ipaddr->
u.
a6.pfxlen = 0;
895 static int qeth_l3_register_addr_entry(
struct qeth_card *card,
921 }
while ((--cnt > 0) && rc);
926 "Registering IP address %s failed\n", buf);
931 static int qeth_l3_deregister_addr_entry(
struct qeth_card *card,
958 static inline u8 qeth_l3_get_qeth_hdr_flags4(
int cast_type)
967 static inline u8 qeth_l3_get_qeth_hdr_flags6(
int cast_type)
979 static int qeth_l3_setadapter_parms(
struct qeth_card *card)
987 "set adapter parameters not supported.\n");
994 "0x%x\n", dev_name(&card->
gdev->dev), rc);
1001 " address failed\n");
1007 static int qeth_l3_default_setassparms_cb(
struct qeth_card *card,
1015 if (cmd->
hdr.return_code == 0) {
1018 card->
options.ipa4.enabled_funcs = cmd->
hdr.ipa_enabled;
1020 card->
options.ipa6.enabled_funcs = cmd->
hdr.ipa_enabled;
1029 card->
info.tx_csum_mask =
1057 static int qeth_l3_send_setassparms(
struct qeth_card *card,
1069 if (len <=
sizeof(
__u32))
1078 #ifdef CONFIG_QETH_IPV6
1079 static int qeth_l3_send_simple_setassparms_ipv6(
struct qeth_card *card,
1086 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1088 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1089 qeth_l3_default_setassparms_cb,
NULL);
1094 static int qeth_l3_send_simple_setassparms(
struct qeth_card *card,
1103 length =
sizeof(
__u32);
1104 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1106 rc = qeth_l3_send_setassparms(card, iob, length, data,
1107 qeth_l3_default_setassparms_cb,
NULL);
1111 static int qeth_l3_start_ipa_arp_processing(
struct qeth_card *card)
1119 "ARP processing not supported on %s!\n",
1127 "Starting ARP processing support for %s failed\n",
1133 static int qeth_l3_start_ipa_ip_fragmentation(
struct qeth_card *card)
1141 "Hardware IP fragmentation not supported on %s\n",
1150 "Starting IP fragmentation support for %s failed\n",
1154 "Hardware IP fragmentation enabled \n");
1158 static int qeth_l3_start_ipa_source_mac(
struct qeth_card *card)
1166 "Inbound source MAC-address not supported on %s\n",
1175 "Starting source MAC-address support for %s failed\n",
1180 static int qeth_l3_start_ipa_vlan(
struct qeth_card *card)
1196 "Starting VLAN support for %s failed\n",
1204 static int qeth_l3_start_ipa_multicast(
struct qeth_card *card)
1212 "Multicast not supported on %s\n",
1221 "Starting multicast support for %s failed\n",
1230 #ifdef CONFIG_QETH_IPV6
1231 static int qeth_l3_softsetup_ipv6(
struct qeth_card *card)
1243 "Activating IPv6 support for %s failed\n",
1247 rc = qeth_l3_send_simple_setassparms(card,
IPA_IPV6,
1251 "Activating IPv6 support for %s failed\n",
1255 rc = qeth_l3_send_simple_setassparms_ipv6(card,
IPA_IPV6,
1259 "Activating IPv6 support for %s failed\n",
1263 rc = qeth_l3_send_simple_setassparms_ipv6(card,
IPA_PASSTHRU,
1267 "Enabling the passthrough mode for %s failed\n",
1277 static int qeth_l3_start_ipa_ipv6(
struct qeth_card *card)
1288 #ifdef CONFIG_QETH_IPV6
1289 rc = qeth_l3_softsetup_ipv6(card);
1294 static int qeth_l3_start_ipa_broadcast(
struct qeth_card *card)
1299 card->
info.broadcast_capable = 0;
1302 "Broadcast not supported on %s\n",
1310 dev_warn(&card->
gdev->dev,
"Enabling broadcast filtering for "
1319 "Setting up broadcast filtering for %s failed\n",
1328 dev_warn(&card->
gdev->dev,
"Setting up broadcast echo "
1334 if (card->
info.broadcast_capable)
1341 static int qeth_l3_send_checksum_command(
struct qeth_card *card)
1348 dev_warn(&card->
gdev->dev,
"Starting HW checksumming for %s "
1349 "failed, using SW checksumming\n",
1355 card->
info.csum_mask);
1357 dev_warn(&card->
gdev->dev,
"Enabling HW checksumming for %s "
1358 "failed, using SW checksumming\n",
1365 static int qeth_l3_set_rx_csum(
struct qeth_card *card,
int on)
1370 rc = qeth_l3_send_checksum_command(card);
1374 "HW Checksumming (inbound) enabled\n");
1376 rc = qeth_l3_send_simple_setassparms(card,
1385 static int qeth_l3_start_ipa_checksum(
struct qeth_card *card)
1399 static int qeth_l3_start_ipa_tx_checksum(
struct qeth_card *card)
1413 dev_info(&card->
gdev->dev,
"HW TX Checksumming enabled\n");
1416 dev_warn(&card->
gdev->dev,
"Enabling HW TX checksumming for %s "
1421 static int qeth_l3_start_ipa_tso(
struct qeth_card *card)
1429 "Outbound TSO not supported on %s\n",
1437 "segmentation offload for %s failed\n",
1441 "Outbound TSO enabled\n");
1448 static int qeth_l3_start_ipassists(
struct qeth_card *card)
1453 qeth_l3_start_ipa_arp_processing(card);
1454 qeth_l3_start_ipa_ip_fragmentation(card);
1455 qeth_l3_start_ipa_source_mac(card);
1456 qeth_l3_start_ipa_vlan(card);
1457 qeth_l3_start_ipa_multicast(card);
1458 qeth_l3_start_ipa_ipv6(card);
1459 qeth_l3_start_ipa_broadcast(card);
1460 qeth_l3_start_ipa_checksum(card);
1461 qeth_l3_start_ipa_tx_checksum(card);
1462 qeth_l3_start_ipa_tso(card);
1466 static int qeth_l3_iqd_read_initial_mac_cb(
struct qeth_card *card,
1467 struct qeth_reply *reply,
unsigned long data)
1472 if (cmd->
hdr.return_code == 0)
1476 eth_random_addr(card->
dev->dev_addr);
1481 static int qeth_l3_iqd_read_initial_mac(
struct qeth_card *card)
1493 card->
info.unique_id;
1500 static int qeth_l3_get_unique_id_cb(
struct qeth_card *card,
1501 struct qeth_reply *reply,
unsigned long data)
1506 if (cmd->
hdr.return_code == 0)
1512 dev_warn(&card->
gdev->dev,
"The network adapter failed to "
1513 "generate a unique ID\n");
1518 static int qeth_l3_get_unique_id(
struct qeth_card *card)
1536 card->
info.unique_id;
1552 rc = cmd->
hdr.return_code;
1564 "traffic analyzer is deactivated\n");
1575 "traffic analyzer is activated\n");
1579 "authorized to run as a HiperSockets network "
1580 "traffic analyzer\n");
1584 "network traffic analyzer is already "
1585 "active in the HiperSockets LAN\n");
1616 static void qeth_l3_get_mac_for_ipm(
__u32 ipm,
char *
mac,
1619 ip_eth_mc_map(ipm, mac);
1622 static void qeth_l3_add_mc(
struct qeth_card *card,
struct in_device *in4_dev)
1631 qeth_l3_get_mac_for_ipm(im4->
multiaddr, buf, in4_dev->dev);
1643 static void qeth_l3_add_vlan_mc(
struct qeth_card *card)
1645 struct in_device *in_dev;
1658 if (netdev ==
NULL ||
1661 in_dev = in_dev_get(netdev);
1665 qeth_l3_add_mc(card, in_dev);
1671 static void qeth_l3_add_multicast_ipv4(
struct qeth_card *card)
1673 struct in_device *in4_dev;
1676 in4_dev = in_dev_get(card->
dev);
1677 if (in4_dev ==
NULL)
1680 qeth_l3_add_mc(card, in4_dev);
1681 qeth_l3_add_vlan_mc(card);
1683 in_dev_put(in4_dev);
1686 #ifdef CONFIG_QETH_IPV6
1708 static void qeth_l3_add_vlan_mc6(
struct qeth_card *card)
1721 if (netdev ==
NULL ||
1724 in_dev = in6_dev_get(netdev);
1728 qeth_l3_add_mc6(card, in_dev);
1730 in6_dev_put(in_dev);
1734 static void qeth_l3_add_multicast_ipv6(
struct qeth_card *card)
1741 in6_dev = in6_dev_get(card->
dev);
1742 if (in6_dev ==
NULL)
1745 qeth_l3_add_mc6(card, in6_dev);
1746 qeth_l3_add_vlan_mc6(card);
1748 in6_dev_put(in6_dev);
1752 static void qeth_l3_free_vlan_addresses4(
struct qeth_card *card,
1755 struct in_device *in_dev;
1756 struct in_ifaddr *ifa;
1765 in_dev = in_dev_get(netdev);
1768 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1771 addr->
u.
a4.addr = ifa->ifa_address;
1772 addr->
u.
a4.mask = ifa->ifa_mask;
1781 static void qeth_l3_free_vlan_addresses6(
struct qeth_card *card,
1784 #ifdef CONFIG_QETH_IPV6
1795 in6_dev = in6_dev_get(netdev);
1809 in6_dev_put(in6_dev);
1813 static void qeth_l3_free_vlan_addresses(
struct qeth_card *card,
1816 qeth_l3_free_vlan_addresses4(card, vid);
1817 qeth_l3_free_vlan_addresses6(card, vid);
1820 static int qeth_l3_vlan_rx_add_vid(
struct net_device *
dev,
unsigned short vid)
1828 static int qeth_l3_vlan_rx_kill_vid(
struct net_device *
dev,
unsigned short vid)
1831 unsigned long flags;
1840 qeth_l3_free_vlan_addresses(card, vid);
1842 spin_unlock_irqrestore(&card->
vlanlock, flags);
1843 qeth_l3_set_multicast_list(card->
dev);
1847 static inline int qeth_l3_rebuild_skb(
struct qeth_card *card,
1852 struct iphdr *ip_hdr;
1862 #ifdef CONFIG_QETH_IPV6
1866 tg_addr, card->dev, 0);
1871 ip_eth_mc_map(ip_hdr->
daddr, tg_addr);
1875 card->
dev->addr_len);
1877 card->
stats.multicast++;
1882 card->
dev->addr_len);
1883 card->
stats.multicast++;
1895 card->
dev->addr_len);
1898 card->
dev->header_ops->create(skb, card->
dev, prot,
1899 tg_addr, &hdr->
hdr.
l3.dest_addr[2],
1900 card->
dev->addr_len);
1902 card->
dev->header_ops->create(skb, card->
dev, prot,
1903 tg_addr,
"FAKELL", card->
dev->addr_len);
1908 if (hdr->
hdr.
l3.ext_flags &
1916 if ((hdr->
hdr.
l3.ext_flags &
1930 static int qeth_l3_process_inbound_buffer(
struct qeth_card *card,
1945 &card->
qdio.in_q->bufs[card->
rx.b_index],
1946 &card->
rx.b_element, &card->
rx.e_offset, &hdr);
1952 switch (hdr->
hdr.
l3.id) {
1962 card->
dev->header_ops->create(skb, card->
dev, 0,
1963 card->
dev->dev_addr,
"FAKELL",
1964 card->
dev->addr_len);
1967 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
1970 if (is_vlan && !card->
options.sniffer)
1971 __vlan_hwaccel_put_tag(skb, vlan_tag);
1989 card->
stats.rx_packets++;
1990 card->
stats.rx_bytes += len;
2001 int new_budget = budget;
2003 if (card->
options.performance_stats) {
2005 card->
perf_stats.inbound_start_time = qeth_get_micros();
2009 if (!card->
rx.b_count) {
2010 card->
rx.qdio_err = 0;
2012 card->
data.ccwdev, 0, &card->
rx.b_index,
2013 &card->
rx.qdio_err);
2014 if (card->
rx.b_count <= 0) {
2015 card->
rx.b_count = 0;
2018 card->
rx.b_element =
2019 &card->
qdio.in_q->bufs[card->
rx.b_index]
2020 .buffer->element[0];
2021 card->
rx.e_offset = 0;
2024 while (card->
rx.b_count) {
2025 buffer = &card->
qdio.in_q->bufs[card->
rx.b_index];
2026 if (!(card->
rx.qdio_err &&
2028 card->
rx.qdio_err,
"qinerr")))
2029 work_done += qeth_l3_process_inbound_buffer(
2030 card, new_budget, &done);
2035 if (card->
options.performance_stats)
2037 qeth_put_buffer_pool_entry(card,
2041 if (card->
rx.b_count) {
2043 (card->
rx.b_index + 1) %
2045 card->
rx.b_element =
2047 ->bufs[card->
rx.b_index]
2048 .buffer->element[0];
2049 card->
rx.e_offset = 0;
2053 if (work_done >= budget)
2056 new_budget = budget - work_done;
2062 napi_schedule(&card->
napi);
2064 if (card->
options.performance_stats)
2065 card->
perf_stats.inbound_time += qeth_get_micros() -
2070 static int qeth_l3_verify_vlan_dev(
struct net_device *dev,
2082 if (netdev == dev) {
2094 static int qeth_l3_verify_dev(
struct net_device *dev)
2097 unsigned long flags;
2102 if (card->
dev == dev) {
2106 rc = qeth_l3_verify_vlan_dev(dev, card);
2120 rc = qeth_l3_verify_dev(dev);
2125 if (card && card->
options.layer2)
2132 static int qeth_l3_stop_card(
struct qeth_card *card,
int recovery_mode)
2147 qeth_l3_stop(card->
dev);
2156 qeth_l3_clear_ip_list(card, 1);
2178 qeth_l3_handle_promisc_mode(
struct qeth_card *card)
2188 if (card->
info.guestlan) {
2191 }
else if (card->
options.sniffer &&
2203 static void qeth_l3_set_multicast_list(
struct net_device *dev)
2212 qeth_l3_delete_mc_addresses(card);
2213 qeth_l3_add_multicast_ipv4(card);
2214 #ifdef CONFIG_QETH_IPV6
2215 qeth_l3_add_multicast_ipv6(card);
2221 qeth_l3_handle_promisc_mode(card);
2224 static const char *qeth_l3_arp_get_error_cause(
int *rc)
2229 return "operation failed";
2232 return "operation not supported";
2235 return "argument out of range";
2238 return "query operation not supported";
2241 return "no query data available";
2243 return "unknown error";
2259 if (card->
info.guestlan)
2271 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2286 if (strip_entries) {
2288 sizeof(struct qeth_arp_qi_entry7_short);
2291 sizeof(struct qeth_arp_qi_entry7);
2295 if (strip_entries) {
2298 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2302 sizeof(struct qeth_arp_qi_entry7_ipv6);
2318 static int qeth_l3_arp_query_cb(
struct qeth_card *card,
2319 struct qeth_reply *reply,
unsigned long data)
2326 int entrybytes_done;
2328 __u8 do_strip_entries;
2335 if (cmd->
hdr.return_code) {
2351 entrybytes_done = 0;
2357 cur_entry = &qdata->
data + entrybytes_done;
2359 if (!arpentry_matches_prot(etype, cmd->
hdr.prot_version)) {
2364 esize = get_arp_entry_size(card, qdata, etype,
2377 &qdata->
data + entrybytes_done + stripped_bytes,
2379 entrybytes_done += esize + stripped_bytes;
2402 static int qeth_l3_send_ipa_arp_cmd(
struct qeth_card *card,
2414 reply_cb, reply_param);
2417 static int qeth_l3_query_arp_cache_info(
struct qeth_card *card,
2436 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2438 qeth_l3_arp_query_cb, (
void *)qinfo);
2442 "Error while querying ARP cache on %s: %s "
2444 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2450 static int qeth_l3_arp_query(
struct qeth_card *card,
char __user *udata)
2480 #ifdef CONFIG_QETH_IPV6
2500 static int qeth_l3_arp_add_entry(
struct qeth_card *card,
2515 if (card->
info.guestlan)
2525 rc = qeth_l3_send_setassparms(card, iob,
2527 (
unsigned long) entry,
2528 qeth_l3_default_setassparms_cb,
NULL);
2534 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2539 static int qeth_l3_arp_remove_entry(
struct qeth_card *card,
2543 char buf[16] = {0, };
2554 if (card->
info.guestlan)
2564 rc = qeth_l3_send_setassparms(card, iob,
2565 12, (
unsigned long)buf,
2566 qeth_l3_default_setassparms_cb,
NULL);
2573 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2578 static int qeth_l3_arp_flush_cache(
struct qeth_card *card)
2601 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2644 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2655 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2662 rc = qeth_l3_arp_flush_cache(card);
2670 !card->
info.guestlan)
2675 mii_data = if_mii(rq);
2679 mii_data = if_mii(rq);
2680 if (mii_data->
phy_id != 0)
2707 n = dst_neigh_lookup_skb(dst, skb);
2709 cast_type = n->
type;
2723 return (skb_network_header(skb)[24] == 0xff) ?
2726 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2734 hdr_mac = *((
u16 *)skb->
data);
2736 switch (card->
info.link_type) {
2753 static void qeth_l3_fill_af_iucv_hdr(
struct qeth_card *card,
2760 card->
dev->header_ops->create(skb, card->
dev, 0,
2761 card->
dev->dev_addr, card->
dev->dev_addr,
2762 card->
dev->addr_len);
2767 hdr->
hdr.
l3.ext_flags = 0;
2770 memset(daddr, 0,
sizeof(daddr));
2778 struct sk_buff *skb,
int ipv,
int cast_type)
2784 hdr->
hdr.
l3.ext_flags = 0;
2810 hdr->
hdr.
l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2812 *((
__be32 *) (&hdr->
hdr.
l3.dest_addr[12])) = *pkey;
2813 }
else if (ipv == 6) {
2815 struct in6_addr *pkey = &ipv6_hdr(skb)->daddr;
2821 hdr->
hdr.
l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2827 skb->
dev->broadcast, 6)) {
2840 static inline void qeth_l3_hdr_csum(
struct qeth_card *card,
2843 struct iphdr *iph = ip_hdr(skb);
2853 if (card->
options.performance_stats)
2857 static void qeth_tso_fill_header(
struct qeth_card *card,
2861 struct tcphdr *tcph = tcp_hdr(skb);
2862 struct iphdr *iph = ip_hdr(skb);
2863 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2870 hdr->
ext.imb_hdr_no = 1;
2871 hdr->
ext.hdr_type = 1;
2872 hdr->
ext.hdr_version = 1;
2873 hdr->
ext.hdr_len = 28;
2875 hdr->
ext.mss = skb_shinfo(skb)->gso_size;
2876 hdr->
ext.dg_hdr_len = (
__u16)(iph->ihl*4 + tcph->doff*4);
2893 static inline int qeth_l3_tso_elements(
struct sk_buff *skb)
2895 unsigned long tcpd = (
unsigned long)tcp_hdr(skb) +
2896 tcp_hdr(skb)->doff * 4;
2897 int tcpd_len = skb->
len - (tcpd - (
unsigned long)skb->
data);
2899 elements += skb_shinfo(skb)->nr_frags;
2908 int elements_needed = 0;
2912 int ipv = qeth_get_ip_version(skb);
2929 card->
stats.tx_carrier_errors++;
2934 (card->
info.broadcast_capable == 0))
2937 if (card->
options.performance_stats) {
2939 card->
perf_stats.outbound_start_time = qeth_get_micros();
2942 large_send = skb_is_gso(skb);
2945 (skb_shinfo(skb)->nr_frags == 0)) {
2964 if (data_offset < 0)
2973 skb_copy_to_linear_data(new_skb, new_skb->
data + 4, 4);
2974 skb_copy_to_linear_data_offset(new_skb, 4,
2975 new_skb->
data + 8, 4);
2976 skb_copy_to_linear_data_offset(new_skb, 8,
2977 new_skb->
data + 12, 4);
2978 tag = (
u16 *)(new_skb->
data + 12);
2984 netif_stop_queue(dev);
2990 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
2991 if (skb_linearize(new_skb))
2993 if (card->
options.performance_stats)
2998 if (large_send && (cast_type ==
RTN_UNSPEC)) {
3002 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3003 qeth_tso_fill_header(card, hdr, new_skb);
3006 if (data_offset < 0) {
3009 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3013 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
3015 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3022 qeth_l3_hdr_csum(card, hdr, new_skb);
3028 if (data_offset >= 0)
3032 elements_needed += elems;
3033 nr_frags = skb_shinfo(new_skb)->nr_frags;
3038 len = ((
unsigned long)tcp_hdr(new_skb) +
3039 tcp_hdr(new_skb)->doff * 4) -
3040 (
unsigned long)new_skb->
data;
3050 elements_needed, data_offset, 0);
3053 card->
stats.tx_packets++;
3057 if (card->
options.performance_stats) {
3065 card->
perf_stats.sg_frags_sent += nr_frags + 1;
3070 if (data_offset >= 0)
3081 netif_wake_queue(dev);
3082 if (card->
options.performance_stats)
3083 card->
perf_stats.outbound_time += qeth_get_micros() -
3088 card->
stats.tx_dropped++;
3089 card->
stats.tx_errors++;
3090 if ((new_skb != skb) && new_skb)
3093 netif_wake_queue(dev);
3097 static int __qeth_l3_open(
struct net_device *dev)
3109 netif_start_queue(dev);
3112 napi_enable(&card->
napi);
3113 napi_schedule(&card->
napi);
3119 static int qeth_l3_open(
struct net_device *dev)
3128 return __qeth_l3_open(dev);
3131 static int qeth_l3_stop(
struct net_device *dev)
3136 netif_tx_disable(dev);
3139 napi_disable(&card->
napi);
3159 static int qeth_l3_set_features(
struct net_device *dev,
3173 err = qeth_l3_set_rx_csum(card, features & NETIF_F_RXCSUM);
3180 static const struct ethtool_ops qeth_l3_ethtool_ops = {
3196 static int qeth_l3_neigh_setup_noarp(
struct neighbour *
n)
3214 .ndo_open = qeth_l3_open,
3215 .ndo_stop = qeth_l3_stop,
3217 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3219 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
3220 .ndo_do_ioctl = qeth_l3_do_ioctl,
3222 .ndo_fix_features = qeth_l3_fix_features,
3223 .ndo_set_features = qeth_l3_set_features,
3224 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3225 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3230 .ndo_open = qeth_l3_open,
3231 .ndo_stop = qeth_l3_stop,
3233 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3235 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
3236 .ndo_do_ioctl = qeth_l3_do_ioctl,
3238 .ndo_fix_features = qeth_l3_fix_features,
3239 .ndo_set_features = qeth_l3_set_features,
3240 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3241 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3243 .ndo_neigh_setup = qeth_l3_neigh_setup,
3246 static int qeth_l3_setup_netdev(
struct qeth_card *card)
3252 pr_info(
"qeth_l3: ignoring TR device\n");
3255 card->
dev = alloc_etherdev(0);
3258 card->
dev->netdev_ops = &qeth_l3_osa_netdev_ops;
3261 qeth_l3_get_unique_id(card);
3263 card->
dev->dev_id = card->
info.unique_id &
3265 if (!card->
info.guestlan) {
3277 card->
dev->netdev_ops = &qeth_l3_netdev_ops;
3278 qeth_l3_iqd_read_initial_mac(card);
3286 card->
dev->mtu = card->
info.initial_mtu;
3305 card->
info.hwtrap = 0;
3318 if (cgdev->
state == CCWGROUP_ONLINE)
3319 qeth_l3_set_offline(cgdev);
3326 qeth_l3_clear_ip_list(card, 0);
3327 qeth_l3_clear_ipato_list(card);
3343 recover_flag = card->
state;
3351 if (!card->
dev && qeth_l3_setup_netdev(card)) {
3357 if (card->
info.hwtrap &&
3359 card->
info.hwtrap = 0;
3361 card->
info.hwtrap = 0;
3375 "The LAN is offline\n");
3385 rc = qeth_l3_setadapter_parms(card);
3389 rc = qeth_l3_start_ipassists(card);
3399 netif_tx_disable(card->
dev);
3418 __qeth_l3_open(card->
dev);
3421 qeth_l3_set_multicast_list(card->
dev);
3430 qeth_l3_stop_card(card, 0);
3445 return __qeth_l3_set_online(gdev, 0);
3452 int rc = 0, rc2 = 0, rc3 = 0;
3460 if (card->
dev && netif_carrier_ok(card->
dev))
3462 recover_flag = card->
state;
3463 if ((!recovery_mode && card->
info.hwtrap) || card->
info.hwtrap == 2) {
3465 card->
info.hwtrap = 1;
3467 qeth_l3_stop_card(card, recovery_mode);
3477 rc = (rc2) ? rc2 : rc3;
3491 return __qeth_l3_set_offline(cgdev, 0);
3494 static int qeth_l3_recover(
void *
ptr)
3506 "A recovery process has been started for the device\n");
3507 __qeth_l3_set_offline(card->
gdev, 1);
3508 rc = __qeth_l3_set_online(card->
gdev, 1);
3511 "Device successfully recovered!\n");
3517 "failed to recover an error on the device\n");
3529 if ((gdev->
state == CCWGROUP_ONLINE) && card->
info.hwtrap)
3543 if (gdev->
state == CCWGROUP_OFFLINE)
3546 if (card->
info.hwtrap)
3548 __qeth_l3_set_offline(card->
gdev, 1);
3550 __qeth_l3_set_offline(card->
gdev, 0);
3559 if (gdev->
state == CCWGROUP_OFFLINE)
3563 rc = __qeth_l3_set_online(card->
gdev, 1);
3570 rc = __qeth_l3_set_online(card->
gdev, 0);
3577 "failed to recover an error on the device\n");
3585 .recover = qeth_l3_recover,
3586 .setup = qeth_l3_probe_device,
3587 .remove = qeth_l3_remove_device,
3588 .set_online = qeth_l3_set_online,
3589 .set_offline = qeth_l3_set_offline,
3590 .shutdown = qeth_l3_shutdown,
3591 .freeze = qeth_l3_pm_suspend,
3592 .thaw = qeth_l3_pm_resume,
3593 .restore = qeth_l3_pm_resume,
3598 unsigned long event,
void *ptr)
3600 struct in_ifaddr *ifa = (
struct in_ifaddr *)ptr;
3608 card = qeth_l3_get_card_from_dev(dev);
3615 addr->
u.
a4.addr = ifa->ifa_address;
3616 addr->
u.
a4.mask = ifa->ifa_mask;
3643 #ifdef CONFIG_QETH_IPV6
3648 unsigned long event,
void *ptr)
3655 card = qeth_l3_get_card_from_dev(dev);
3693 static int qeth_l3_register_notifiers(
void)
3701 #ifdef CONFIG_QETH_IPV6
3708 pr_warning(
"There is no IPv6 support for the layer 3 discipline\n");
3713 static void qeth_l3_unregister_notifiers(
void)
3718 #ifdef CONFIG_QETH_IPV6
3723 static int __init qeth_l3_init(
void)
3727 pr_info(
"register layer 3 discipline\n");
3728 rc = qeth_l3_register_notifiers();
3732 static void __exit qeth_l3_exit(
void)
3734 qeth_l3_unregister_notifiers();
3735 pr_info(
"unregister layer 3 discipline\n");