Commit 615fa143 authored by Daniel Ritz's avatar Daniel Ritz Committed by Jeff Garzik

[PATCH] strip.c: don't allocate net_device as part of private struct

hi jeff

cleans up strip.c not to allocate struct net_device as part of the private
structure. use a separate kmalloc (and kfree). compile tested only.
against 2.5.73-bk

-daniel
parent b6769972
...@@ -284,7 +284,7 @@ struct strip { ...@@ -284,7 +284,7 @@ struct strip {
*/ */
struct tty_struct *tty; /* ptr to TTY structure */ struct tty_struct *tty; /* ptr to TTY structure */
struct net_device dev; /* Our device structure */ struct net_device *dev; /* Our device structure */
/* /*
* Neighbour radio records * Neighbour radio records
...@@ -509,7 +509,7 @@ static void DumpData(char *msg, struct strip *strip_info, __u8 * ptr, ...@@ -509,7 +509,7 @@ static void DumpData(char *msg, struct strip *strip_info, __u8 * ptr,
*p++ = '\"'; *p++ = '\"';
*p++ = 0; *p++ = 0;
printk(KERN_INFO "%s: %-13s%s\n", strip_info->dev.name, msg, pkt_text); printk(KERN_INFO "%s: %-13s%s\n", strip_info->dev->name, msg, pkt_text);
} }
...@@ -846,7 +846,7 @@ static __u8 *radio_address_to_string(const MetricomAddress * addr, ...@@ -846,7 +846,7 @@ static __u8 *radio_address_to_string(const MetricomAddress * addr,
static int allocate_buffers(struct strip *strip_info) static int allocate_buffers(struct strip *strip_info)
{ {
struct net_device *dev = &strip_info->dev; struct net_device *dev = strip_info->dev;
int sx_size = MAX(STRIP_ENCAP_SIZE(MAX_RECV_MTU), 4096); int sx_size = MAX(STRIP_ENCAP_SIZE(MAX_RECV_MTU), 4096);
int tx_size = STRIP_ENCAP_SIZE(dev->mtu) + MaxCommandStringLength; int tx_size = STRIP_ENCAP_SIZE(dev->mtu) + MaxCommandStringLength;
__u8 *r = kmalloc(MAX_RECV_MTU, GFP_ATOMIC); __u8 *r = kmalloc(MAX_RECV_MTU, GFP_ATOMIC);
...@@ -881,7 +881,7 @@ static int allocate_buffers(struct strip *strip_info) ...@@ -881,7 +881,7 @@ static int allocate_buffers(struct strip *strip_info)
static void strip_changedmtu(struct strip *strip_info) static void strip_changedmtu(struct strip *strip_info)
{ {
int old_mtu = strip_info->mtu; int old_mtu = strip_info->mtu;
struct net_device *dev = &strip_info->dev; struct net_device *dev = strip_info->dev;
unsigned char *orbuff = strip_info->rx_buff; unsigned char *orbuff = strip_info->rx_buff;
unsigned char *osbuff = strip_info->sx_buff; unsigned char *osbuff = strip_info->sx_buff;
unsigned char *otbuff = strip_info->tx_buff; unsigned char *otbuff = strip_info->tx_buff;
...@@ -889,14 +889,14 @@ static void strip_changedmtu(struct strip *strip_info) ...@@ -889,14 +889,14 @@ static void strip_changedmtu(struct strip *strip_info)
if (dev->mtu > MAX_SEND_MTU) { if (dev->mtu > MAX_SEND_MTU) {
printk(KERN_ERR printk(KERN_ERR
"%s: MTU exceeds maximum allowable (%d), MTU change cancelled.\n", "%s: MTU exceeds maximum allowable (%d), MTU change cancelled.\n",
strip_info->dev.name, MAX_SEND_MTU); strip_info->dev->name, MAX_SEND_MTU);
dev->mtu = old_mtu; dev->mtu = old_mtu;
return; return;
} }
if (!allocate_buffers(strip_info)) { if (!allocate_buffers(strip_info)) {
printk(KERN_ERR "%s: unable to grow strip buffers, MTU change cancelled.\n", printk(KERN_ERR "%s: unable to grow strip buffers, MTU change cancelled.\n",
strip_info->dev.name); strip_info->dev->name);
dev->mtu = old_mtu; dev->mtu = old_mtu;
return; return;
} }
...@@ -923,7 +923,7 @@ static void strip_changedmtu(struct strip *strip_info) ...@@ -923,7 +923,7 @@ static void strip_changedmtu(struct strip *strip_info)
strip_info->tx_head = strip_info->tx_buff; strip_info->tx_head = strip_info->tx_buff;
printk(KERN_NOTICE "%s: strip MTU changed fom %d to %d.\n", printk(KERN_NOTICE "%s: strip MTU changed fom %d to %d.\n",
strip_info->dev.name, old_mtu, strip_info->mtu); strip_info->dev->name, old_mtu, strip_info->mtu);
if (orbuff) if (orbuff)
kfree(orbuff); kfree(orbuff);
...@@ -940,7 +940,7 @@ static void strip_unlock(struct strip *strip_info) ...@@ -940,7 +940,7 @@ static void strip_unlock(struct strip *strip_info)
*/ */
strip_info->idle_timer.expires = jiffies + 1 * HZ; strip_info->idle_timer.expires = jiffies + 1 * HZ;
add_timer(&strip_info->idle_timer); add_timer(&strip_info->idle_timer);
netif_wake_queue(&strip_info->dev); netif_wake_queue(strip_info->dev);
} }
...@@ -1087,10 +1087,10 @@ static int sprintf_status_info(char *buffer, struct strip *strip_info) ...@@ -1087,10 +1087,10 @@ static int sprintf_status_info(char *buffer, struct strip *strip_info)
FirmwareVersion firmware_version = strip_info->firmware_version; FirmwareVersion firmware_version = strip_info->firmware_version;
SerialNumber serial_number = strip_info->serial_number; SerialNumber serial_number = strip_info->serial_number;
BatteryVoltage battery_voltage = strip_info->battery_voltage; BatteryVoltage battery_voltage = strip_info->battery_voltage;
char *if_name = strip_info->dev.name; char *if_name = strip_info->dev->name;
MetricomAddress true_dev_addr = strip_info->true_dev_addr; MetricomAddress true_dev_addr = strip_info->true_dev_addr;
MetricomAddress dev_dev_addr = MetricomAddress dev_dev_addr =
*(MetricomAddress *) strip_info->dev.dev_addr; *(MetricomAddress *) strip_info->dev->dev_addr;
int manual_dev_addr = strip_info->manual_dev_addr; int manual_dev_addr = strip_info->manual_dev_addr;
#ifdef EXT_COUNTERS #ifdef EXT_COUNTERS
unsigned long rx_bytes = strip_info->rx_bytes; unsigned long rx_bytes = strip_info->rx_bytes;
...@@ -1133,7 +1133,7 @@ static int sprintf_status_info(char *buffer, struct strip *strip_info) ...@@ -1133,7 +1133,7 @@ static int sprintf_status_info(char *buffer, struct strip *strip_info)
p += sprintf(p, " Next gratuitous ARP:\t"); p += sprintf(p, " Next gratuitous ARP:\t");
if (!memcmp if (!memcmp
(strip_info->dev.dev_addr, zero_address.c, (strip_info->dev->dev_addr, zero_address.c,
sizeof(zero_address))) sizeof(zero_address)))
p += sprintf(p, "Disabled\n"); p += sprintf(p, "Disabled\n");
else { else {
...@@ -1210,7 +1210,7 @@ static void ResetRadio(struct strip *strip_info) ...@@ -1210,7 +1210,7 @@ static void ResetRadio(struct strip *strip_info)
*/ */
if (strip_info->working) { if (strip_info->working) {
printk(KERN_INFO "%s: No response: Resetting radio.\n", printk(KERN_INFO "%s: No response: Resetting radio.\n",
strip_info->dev.name); strip_info->dev->name);
strip_info->firmware_version.c[0] = '\0'; strip_info->firmware_version.c[0] = '\0';
strip_info->serial_number.c[0] = '\0'; strip_info->serial_number.c[0] = '\0';
strip_info->battery_voltage.c[0] = '\0'; strip_info->battery_voltage.c[0] = '\0';
...@@ -1231,7 +1231,7 @@ static void ResetRadio(struct strip *strip_info) ...@@ -1231,7 +1231,7 @@ static void ResetRadio(struct strip *strip_info)
/* Mark radio address as unknown */ /* Mark radio address as unknown */
*(MetricomAddress *) & strip_info->true_dev_addr = zero_address; *(MetricomAddress *) & strip_info->true_dev_addr = zero_address;
if (!strip_info->manual_dev_addr) if (!strip_info->manual_dev_addr)
*(MetricomAddress *) strip_info->dev.dev_addr = *(MetricomAddress *) strip_info->dev->dev_addr =
zero_address; zero_address;
strip_info->working = FALSE; strip_info->working = FALSE;
strip_info->firmware_level = NoStructure; strip_info->firmware_level = NoStructure;
...@@ -1285,7 +1285,7 @@ static void strip_write_some_more(struct tty_struct *tty) ...@@ -1285,7 +1285,7 @@ static void strip_write_some_more(struct tty_struct *tty)
/* First make sure we're connected. */ /* First make sure we're connected. */
if (!strip_info || strip_info->magic != STRIP_MAGIC || if (!strip_info || strip_info->magic != STRIP_MAGIC ||
!netif_running(&strip_info->dev)) !netif_running(strip_info->dev))
return; return;
if (strip_info->tx_left > 0) { if (strip_info->tx_left > 0) {
...@@ -1340,14 +1340,14 @@ static unsigned char *strip_make_packet(unsigned char *buffer, ...@@ -1340,14 +1340,14 @@ static unsigned char *strip_make_packet(unsigned char *buffer,
else { else {
printk(KERN_ERR printk(KERN_ERR
"%s: strip_make_packet: Unknown packet type 0x%04X\n", "%s: strip_make_packet: Unknown packet type 0x%04X\n",
strip_info->dev.name, ntohs(header->protocol)); strip_info->dev->name, ntohs(header->protocol));
return (NULL); return (NULL);
} }
if (len > strip_info->mtu) { if (len > strip_info->mtu) {
printk(KERN_ERR printk(KERN_ERR
"%s: Dropping oversized transmit packet: %d bytes\n", "%s: Dropping oversized transmit packet: %d bytes\n",
strip_info->dev.name, len); strip_info->dev->name, len);
return (NULL); return (NULL);
} }
...@@ -1357,7 +1357,7 @@ static unsigned char *strip_make_packet(unsigned char *buffer, ...@@ -1357,7 +1357,7 @@ static unsigned char *strip_make_packet(unsigned char *buffer,
*/ */
if (!memcmp(haddr.c, strip_info->true_dev_addr.c, sizeof(haddr))) { if (!memcmp(haddr.c, strip_info->true_dev_addr.c, sizeof(haddr))) {
printk(KERN_ERR "%s: Dropping packet addressed to self\n", printk(KERN_ERR "%s: Dropping packet addressed to self\n",
strip_info->dev.name); strip_info->dev->name);
return (NULL); return (NULL);
} }
...@@ -1367,7 +1367,7 @@ static unsigned char *strip_make_packet(unsigned char *buffer, ...@@ -1367,7 +1367,7 @@ static unsigned char *strip_make_packet(unsigned char *buffer,
*/ */
if (haddr.c[0] == 0xFF) { if (haddr.c[0] == 0xFF) {
u32 brd = 0; u32 brd = 0;
struct in_device *in_dev = in_dev_get(&strip_info->dev); struct in_device *in_dev = in_dev_get(strip_info->dev);
if (in_dev == NULL) if (in_dev == NULL)
return NULL; return NULL;
read_lock(&in_dev->lock); read_lock(&in_dev->lock);
...@@ -1377,10 +1377,10 @@ static unsigned char *strip_make_packet(unsigned char *buffer, ...@@ -1377,10 +1377,10 @@ static unsigned char *strip_make_packet(unsigned char *buffer,
in_dev_put(in_dev); in_dev_put(in_dev);
/* arp_query returns 1 if it succeeds in looking up the address, 0 if it fails */ /* arp_query returns 1 if it succeeds in looking up the address, 0 if it fails */
if (!arp_query(haddr.c, brd, &strip_info->dev)) { if (!arp_query(haddr.c, brd, strip_info->dev)) {
printk(KERN_ERR printk(KERN_ERR
"%s: Unable to send packet (no broadcast hub configured)\n", "%s: Unable to send packet (no broadcast hub configured)\n",
strip_info->dev.name); strip_info->dev->name);
return (NULL); return (NULL);
} }
/* /*
...@@ -1491,7 +1491,7 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb) ...@@ -1491,7 +1491,7 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb)
#endif #endif
strip_info->watchdog_doprobe = jiffies + 10 * HZ; strip_info->watchdog_doprobe = jiffies + 10 * HZ;
strip_info->watchdog_doreset = jiffies + 1 * HZ; strip_info->watchdog_doreset = jiffies + 1 * HZ;
/*printk(KERN_INFO "%s: Routine radio test.\n", strip_info->dev.name); */ /*printk(KERN_INFO "%s: Routine radio test.\n", strip_info->dev->name); */
} }
/* /*
...@@ -1506,7 +1506,7 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb) ...@@ -1506,7 +1506,7 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb)
*/ */
if (strip_info->tx_size - strip_info->tx_left < 20) if (strip_info->tx_size - strip_info->tx_left < 20)
printk(KERN_ERR "%s: Sending%5d bytes;%5d bytes free.\n", printk(KERN_ERR "%s: Sending%5d bytes;%5d bytes free.\n",
strip_info->dev.name, strip_info->tx_left, strip_info->dev->name, strip_info->tx_left,
strip_info->tx_size - strip_info->tx_left); strip_info->tx_size - strip_info->tx_left);
/* /*
...@@ -1519,7 +1519,7 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb) ...@@ -1519,7 +1519,7 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb)
} }
if (1) { if (1) {
struct in_device *in_dev = in_dev_get(&strip_info->dev); struct in_device *in_dev = in_dev_get(strip_info->dev);
brd = addr = 0; brd = addr = 0;
if (in_dev) { if (in_dev) {
read_lock(&in_dev->lock); read_lock(&in_dev->lock);
...@@ -1549,11 +1549,11 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb) ...@@ -1549,11 +1549,11 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb)
*/ */
if (strip_info->working if (strip_info->working
&& (long) jiffies - strip_info->gratuitous_arp >= 0 && (long) jiffies - strip_info->gratuitous_arp >= 0
&& memcmp(strip_info->dev.dev_addr, zero_address.c, && memcmp(strip_info->dev->dev_addr, zero_address.c,
sizeof(zero_address)) sizeof(zero_address))
&& arp_query(haddr.c, brd, &strip_info->dev)) { && arp_query(haddr.c, brd, strip_info->dev)) {
/*printk(KERN_INFO "%s: Sending gratuitous ARP with interval %ld\n", /*printk(KERN_INFO "%s: Sending gratuitous ARP with interval %ld\n",
strip_info->dev.name, strip_info->arp_interval / HZ); */ strip_info->dev->name, strip_info->arp_interval / HZ); */
strip_info->gratuitous_arp = strip_info->gratuitous_arp =
jiffies + strip_info->arp_interval; jiffies + strip_info->arp_interval;
strip_info->arp_interval *= 2; strip_info->arp_interval *= 2;
...@@ -1561,11 +1561,11 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb) ...@@ -1561,11 +1561,11 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb)
strip_info->arp_interval = MaxARPInterval; strip_info->arp_interval = MaxARPInterval;
if (addr) if (addr)
arp_send(ARPOP_REPLY, ETH_P_ARP, addr, /* Target address of ARP packet is our address */ arp_send(ARPOP_REPLY, ETH_P_ARP, addr, /* Target address of ARP packet is our address */
&strip_info->dev, /* Device to send packet on */ strip_info->dev, /* Device to send packet on */
addr, /* Source IP address this ARP packet comes from */ addr, /* Source IP address this ARP packet comes from */
NULL, /* Destination HW address is NULL (broadcast it) */ NULL, /* Destination HW address is NULL (broadcast it) */
strip_info->dev.dev_addr, /* Source HW address is our HW address */ strip_info->dev->dev_addr, /* Source HW address is our HW address */
strip_info->dev.dev_addr); /* Target HW address is our HW address (redundant) */ strip_info->dev->dev_addr); /* Target HW address is our HW address (redundant) */
} }
/* /*
...@@ -1608,18 +1608,18 @@ static int strip_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -1608,18 +1608,18 @@ static int strip_xmit(struct sk_buff *skb, struct net_device *dev)
if (rx_pps_count / 8 >= 10) if (rx_pps_count / 8 >= 10)
printk(KERN_INFO "%s: WARNING: Receiving %ld packets per second.\n", printk(KERN_INFO "%s: WARNING: Receiving %ld packets per second.\n",
strip_info->dev.name, rx_pps_count / 8); strip_info->dev->name, rx_pps_count / 8);
if (tx_pps_count / 8 >= 10) if (tx_pps_count / 8 >= 10)
printk(KERN_INFO "%s: WARNING: Tx %ld packets per second.\n", printk(KERN_INFO "%s: WARNING: Tx %ld packets per second.\n",
strip_info->dev.name, tx_pps_count / 8); strip_info->dev->name, tx_pps_count / 8);
if (sx_pps_count / 8 >= 10) if (sx_pps_count / 8 >= 10)
printk(KERN_INFO "%s: WARNING: Sending %ld packets per second.\n", printk(KERN_INFO "%s: WARNING: Sending %ld packets per second.\n",
strip_info->dev.name, sx_pps_count / 8); strip_info->dev->name, sx_pps_count / 8);
} }
spin_lock_irqsave(&strip_lock, flags); spin_lock_irqsave(&strip_lock, flags);
/* See if someone has been ifconfigging */ /* See if someone has been ifconfigging */
if (strip_info->mtu != strip_info->dev.mtu) if (strip_info->mtu != strip_info->dev->mtu)
strip_changedmtu(strip_info); strip_changedmtu(strip_info);
strip_send(strip_info, skb); strip_send(strip_info, skb);
...@@ -1735,7 +1735,7 @@ static void get_radio_version(struct strip *strip_info, __u8 * ptr, __u8 * end) ...@@ -1735,7 +1735,7 @@ static void get_radio_version(struct strip *strip_info, __u8 * ptr, __u8 * end)
len = MIN(len, sizeof(FirmwareVersion) - 1); len = MIN(len, sizeof(FirmwareVersion) - 1);
if (strip_info->firmware_version.c[0] == 0) if (strip_info->firmware_version.c[0] == 0)
printk(KERN_INFO "%s: Radio Firmware: %.*s\n", printk(KERN_INFO "%s: Radio Firmware: %.*s\n",
strip_info->dev.name, len, value_begin); strip_info->dev->name, len, value_begin);
sprintf(strip_info->firmware_version.c, "%.*s", len, value_begin); sprintf(strip_info->firmware_version.c, "%.*s", len, value_begin);
/* Look for the first colon */ /* Look for the first colon */
...@@ -1806,10 +1806,10 @@ static int get_radio_address(struct strip *strip_info, __u8 * p) ...@@ -1806,10 +1806,10 @@ static int get_radio_address(struct strip *strip_info, __u8 * p)
MetricomAddressString addr_string; MetricomAddressString addr_string;
radio_address_to_string(&addr, &addr_string); radio_address_to_string(&addr, &addr_string);
printk(KERN_INFO "%s: Radio address = %s\n", printk(KERN_INFO "%s: Radio address = %s\n",
strip_info->dev.name, addr_string.c); strip_info->dev->name, addr_string.c);
strip_info->true_dev_addr = addr; strip_info->true_dev_addr = addr;
if (!strip_info->manual_dev_addr) if (!strip_info->manual_dev_addr)
*(MetricomAddress *) strip_info->dev.dev_addr = *(MetricomAddress *) strip_info->dev->dev_addr =
addr; addr;
/* Give the radio a few seconds to get its head straight, then send an arp */ /* Give the radio a few seconds to get its head straight, then send an arp */
strip_info->gratuitous_arp = jiffies + 15 * HZ; strip_info->gratuitous_arp = jiffies + 15 * HZ;
...@@ -1830,7 +1830,7 @@ static int verify_checksum(struct strip *strip_info) ...@@ -1830,7 +1830,7 @@ static int verify_checksum(struct strip *strip_info)
if (sum == 0 && strip_info->firmware_level == StructuredMessages) { if (sum == 0 && strip_info->firmware_level == StructuredMessages) {
strip_info->firmware_level = ChecksummedMessages; strip_info->firmware_level = ChecksummedMessages;
printk(KERN_INFO "%s: Radio provides message checksums\n", printk(KERN_INFO "%s: Radio provides message checksums\n",
strip_info->dev.name); strip_info->dev->name);
} }
return (sum == 0); return (sum == 0);
} }
...@@ -1849,7 +1849,7 @@ static void RecvErr_Message(struct strip *strip_info, __u8 * sendername, ...@@ -1849,7 +1849,7 @@ static void RecvErr_Message(struct strip *strip_info, __u8 * sendername,
if (has_prefix(msg, len, "001")) { /* Not in StarMode! */ if (has_prefix(msg, len, "001")) { /* Not in StarMode! */
RecvErr("Error Msg:", strip_info); RecvErr("Error Msg:", strip_info);
printk(KERN_INFO "%s: Radio %s is not in StarMode\n", printk(KERN_INFO "%s: Radio %s is not in StarMode\n",
strip_info->dev.name, sendername); strip_info->dev->name, sendername);
} }
else if (has_prefix(msg, len, "002")) { /* Remap handle */ else if (has_prefix(msg, len, "002")) { /* Remap handle */
...@@ -1859,7 +1859,7 @@ static void RecvErr_Message(struct strip *strip_info, __u8 * sendername, ...@@ -1859,7 +1859,7 @@ static void RecvErr_Message(struct strip *strip_info, __u8 * sendername,
else if (has_prefix(msg, len, "003")) { /* Can't resolve name */ else if (has_prefix(msg, len, "003")) { /* Can't resolve name */
RecvErr("Error Msg:", strip_info); RecvErr("Error Msg:", strip_info);
printk(KERN_INFO "%s: Destination radio name is unknown\n", printk(KERN_INFO "%s: Destination radio name is unknown\n",
strip_info->dev.name); strip_info->dev->name);
} }
else if (has_prefix(msg, len, "004")) { /* Name too small or missing */ else if (has_prefix(msg, len, "004")) { /* Name too small or missing */
...@@ -1876,7 +1876,7 @@ static void RecvErr_Message(struct strip *strip_info, __u8 * sendername, ...@@ -1876,7 +1876,7 @@ static void RecvErr_Message(struct strip *strip_info, __u8 * sendername,
if (!strip_info->working) { if (!strip_info->working) {
strip_info->working = TRUE; strip_info->working = TRUE;
printk(KERN_INFO "%s: Radio now in starmode\n", printk(KERN_INFO "%s: Radio now in starmode\n",
strip_info->dev.name); strip_info->dev->name);
/* /*
* If the radio has just entered a working state, we should do our first * If the radio has just entered a working state, we should do our first
* probe ASAP, so that we find out our radio address etc. without delay. * probe ASAP, so that we find out our radio address etc. without delay.
...@@ -1888,7 +1888,7 @@ static void RecvErr_Message(struct strip *strip_info, __u8 * sendername, ...@@ -1888,7 +1888,7 @@ static void RecvErr_Message(struct strip *strip_info, __u8 * sendername,
strip_info->next_command = 0; /* Try to enable checksums ASAP */ strip_info->next_command = 0; /* Try to enable checksums ASAP */
printk(KERN_INFO printk(KERN_INFO
"%s: Radio provides structured messages\n", "%s: Radio provides structured messages\n",
strip_info->dev.name); strip_info->dev->name);
} }
if (strip_info->firmware_level >= StructuredMessages) { if (strip_info->firmware_level >= StructuredMessages) {
/* /*
...@@ -1916,14 +1916,14 @@ static void RecvErr_Message(struct strip *strip_info, __u8 * sendername, ...@@ -1916,14 +1916,14 @@ static void RecvErr_Message(struct strip *strip_info, __u8 * sendername,
RecvErr("Error Msg:", strip_info); RecvErr("Error Msg:", strip_info);
printk(KERN_ERR printk(KERN_ERR
"%s: Error! Packet size too big for radio.\n", "%s: Error! Packet size too big for radio.\n",
strip_info->dev.name); strip_info->dev->name);
} }
else if (has_prefix(msg, len, "008")) { /* Bad character in name */ else if (has_prefix(msg, len, "008")) { /* Bad character in name */
RecvErr("Error Msg:", strip_info); RecvErr("Error Msg:", strip_info);
printk(KERN_ERR printk(KERN_ERR
"%s: Radio name contains illegal character\n", "%s: Radio name contains illegal character\n",
strip_info->dev.name); strip_info->dev->name);
} }
else if (has_prefix(msg, len, "009")) /* No count or line terminator */ else if (has_prefix(msg, len, "009")) /* No count or line terminator */
...@@ -1994,7 +1994,7 @@ static struct net_device *get_strip_dev(struct strip *strip_info) ...@@ -1994,7 +1994,7 @@ static struct net_device *get_strip_dev(struct strip *strip_info)
/* real radio hardware address, try to find another strip device that has been */ /* real radio hardware address, try to find another strip device that has been */
/* manually set to that address that we can 'transfer ownership' of this packet to */ /* manually set to that address that we can 'transfer ownership' of this packet to */
if (strip_info->manual_dev_addr && if (strip_info->manual_dev_addr &&
!memcmp(strip_info->dev.dev_addr, zero_address.c, !memcmp(strip_info->dev->dev_addr, zero_address.c,
sizeof(zero_address)) sizeof(zero_address))
&& memcmp(&strip_info->true_dev_addr, zero_address.c, && memcmp(&strip_info->true_dev_addr, zero_address.c,
sizeof(zero_address))) { sizeof(zero_address))) {
...@@ -2002,13 +2002,13 @@ static struct net_device *get_strip_dev(struct strip *strip_info) ...@@ -2002,13 +2002,13 @@ static struct net_device *get_strip_dev(struct strip *strip_info)
read_lock_bh(&dev_base_lock); read_lock_bh(&dev_base_lock);
dev = dev_base; dev = dev_base;
while (dev) { while (dev) {
if (dev->type == strip_info->dev.type && if (dev->type == strip_info->dev->type &&
!memcmp(dev->dev_addr, !memcmp(dev->dev_addr,
&strip_info->true_dev_addr, &strip_info->true_dev_addr,
sizeof(MetricomAddress))) { sizeof(MetricomAddress))) {
printk(KERN_INFO printk(KERN_INFO
"%s: Transferred packet ownership to %s.\n", "%s: Transferred packet ownership to %s.\n",
strip_info->dev.name, dev->name); strip_info->dev->name, dev->name);
read_unlock_bh(&dev_base_lock); read_unlock_bh(&dev_base_lock);
return (dev); return (dev);
} }
...@@ -2016,7 +2016,7 @@ static struct net_device *get_strip_dev(struct strip *strip_info) ...@@ -2016,7 +2016,7 @@ static struct net_device *get_strip_dev(struct strip *strip_info)
} }
read_unlock_bh(&dev_base_lock); read_unlock_bh(&dev_base_lock);
} }
return (&strip_info->dev); return (strip_info->dev);
} }
/* /*
...@@ -2029,7 +2029,7 @@ static void deliver_packet(struct strip *strip_info, STRIP_Header * header, ...@@ -2029,7 +2029,7 @@ static void deliver_packet(struct strip *strip_info, STRIP_Header * header,
struct sk_buff *skb = dev_alloc_skb(sizeof(STRIP_Header) + packetlen); struct sk_buff *skb = dev_alloc_skb(sizeof(STRIP_Header) + packetlen);
if (!skb) { if (!skb) {
printk(KERN_ERR "%s: memory squeeze, dropping packet.\n", printk(KERN_ERR "%s: memory squeeze, dropping packet.\n",
strip_info->dev.name); strip_info->dev->name);
strip_info->rx_dropped++; strip_info->rx_dropped++;
} else { } else {
memcpy(skb_put(skb, sizeof(STRIP_Header)), header, memcpy(skb_put(skb, sizeof(STRIP_Header)), header,
...@@ -2073,12 +2073,12 @@ static void process_IP_packet(struct strip *strip_info, ...@@ -2073,12 +2073,12 @@ static void process_IP_packet(struct strip *strip_info,
if (packetlen > MAX_RECV_MTU) { if (packetlen > MAX_RECV_MTU) {
printk(KERN_INFO "%s: Dropping oversized received IP packet: %d bytes\n", printk(KERN_INFO "%s: Dropping oversized received IP packet: %d bytes\n",
strip_info->dev.name, packetlen); strip_info->dev->name, packetlen);
strip_info->rx_dropped++; strip_info->rx_dropped++;
return; return;
} }
/*printk(KERN_INFO "%s: Got %d byte IP packet\n", strip_info->dev.name, packetlen); */ /*printk(KERN_INFO "%s: Got %d byte IP packet\n", strip_info->dev->name, packetlen); */
/* Decode remainder of the IP packet */ /* Decode remainder of the IP packet */
ptr = ptr =
...@@ -2117,13 +2117,13 @@ static void process_ARP_packet(struct strip *strip_info, ...@@ -2117,13 +2117,13 @@ static void process_ARP_packet(struct strip *strip_info,
if (packetlen > MAX_RECV_MTU) { if (packetlen > MAX_RECV_MTU) {
printk(KERN_INFO printk(KERN_INFO
"%s: Dropping oversized received ARP packet: %d bytes\n", "%s: Dropping oversized received ARP packet: %d bytes\n",
strip_info->dev.name, packetlen); strip_info->dev->name, packetlen);
strip_info->rx_dropped++; strip_info->rx_dropped++;
return; return;
} }
/*printk(KERN_INFO "%s: Got %d byte ARP %s\n", /*printk(KERN_INFO "%s: Got %d byte ARP %s\n",
strip_info->dev.name, packetlen, strip_info->dev->name, packetlen,
ntohs(arphdr->ar_op) == ARPOP_REQUEST ? "request" : "reply"); */ ntohs(arphdr->ar_op) == ARPOP_REQUEST ? "request" : "reply"); */
/* Decode remainder of the ARP packet */ /* Decode remainder of the ARP packet */
...@@ -2251,7 +2251,7 @@ static void process_message(struct strip *strip_info) ...@@ -2251,7 +2251,7 @@ static void process_message(struct strip *strip_info)
} }
} }
/*printk(KERN_INFO "%s: Got packet from \"%s\".\n", strip_info->dev.name, sendername); */ /*printk(KERN_INFO "%s: Got packet from \"%s\".\n", strip_info->dev->name, sendername); */
/* /*
* Fill in (pseudo) source and destination addresses in the packet. * Fill in (pseudo) source and destination addresses in the packet.
...@@ -2320,13 +2320,13 @@ static void strip_receive_buf(struct tty_struct *tty, const unsigned char *cp, ...@@ -2320,13 +2320,13 @@ static void strip_receive_buf(struct tty_struct *tty, const unsigned char *cp,
unsigned long flags; unsigned long flags;
if (!strip_info || strip_info->magic != STRIP_MAGIC if (!strip_info || strip_info->magic != STRIP_MAGIC
|| !netif_running(&strip_info->dev)) || !netif_running(strip_info->dev))
return; return;
spin_lock_irqsave(&strip_lock, flags); spin_lock_irqsave(&strip_lock, flags);
/* Argh! mtu change time! - costs us the packet part received at the change */ /* Argh! mtu change time! - costs us the packet part received at the change */
if (strip_info->mtu != strip_info->dev.mtu) if (strip_info->mtu != strip_info->dev->mtu)
strip_changedmtu(strip_info); strip_changedmtu(strip_info);
#if 0 #if 0
...@@ -2347,7 +2347,7 @@ static void strip_receive_buf(struct tty_struct *tty, const unsigned char *cp, ...@@ -2347,7 +2347,7 @@ static void strip_receive_buf(struct tty_struct *tty, const unsigned char *cp,
while (cp < end) { while (cp < end) {
if (fp && *fp) if (fp && *fp)
printk(KERN_INFO "%s: %s on serial port\n", printk(KERN_INFO "%s: %s on serial port\n",
strip_info->dev.name, TTYERROR(*fp)); strip_info->dev->name, TTYERROR(*fp));
if (fp && *fp++ && !strip_info->discard) { /* If there's a serial error, record it */ if (fp && *fp++ && !strip_info->discard) { /* If there's a serial error, record it */
/* If we have some characters in the buffer, discard them */ /* If we have some characters in the buffer, discard them */
strip_info->discard = strip_info->sx_count; strip_info->discard = strip_info->sx_count;
...@@ -2360,7 +2360,7 @@ static void strip_receive_buf(struct tty_struct *tty, const unsigned char *cp, ...@@ -2360,7 +2360,7 @@ static void strip_receive_buf(struct tty_struct *tty, const unsigned char *cp,
if (strip_info->sx_count > 3000) if (strip_info->sx_count > 3000)
printk(KERN_INFO printk(KERN_INFO
"%s: Cut a %d byte packet (%d bytes remaining)%s\n", "%s: Cut a %d byte packet (%d bytes remaining)%s\n",
strip_info->dev.name, strip_info->dev->name,
strip_info->sx_count, strip_info->sx_count,
end - cp - 1, end - cp - 1,
strip_info-> strip_info->
...@@ -2371,12 +2371,12 @@ static void strip_receive_buf(struct tty_struct *tty, const unsigned char *cp, ...@@ -2371,12 +2371,12 @@ static void strip_receive_buf(struct tty_struct *tty, const unsigned char *cp,
strip_info->rx_over_errors++; strip_info->rx_over_errors++;
printk(KERN_INFO printk(KERN_INFO
"%s: sx_buff overflow (%d bytes total)\n", "%s: sx_buff overflow (%d bytes total)\n",
strip_info->dev.name, strip_info->dev->name,
strip_info->sx_count); strip_info->sx_count);
} else if (strip_info->discard) } else if (strip_info->discard)
printk(KERN_INFO printk(KERN_INFO
"%s: Discarding bad packet (%d/%d)\n", "%s: Discarding bad packet (%d/%d)\n",
strip_info->dev.name, strip_info->dev->name,
strip_info->discard, strip_info->discard,
strip_info->sx_count); strip_info->sx_count);
else else
...@@ -2415,9 +2415,9 @@ static int set_mac_address(struct strip *strip_info, ...@@ -2415,9 +2415,9 @@ static int set_mac_address(struct strip *strip_info,
memcmp(addr->c, broadcast_address.c, memcmp(addr->c, broadcast_address.c,
sizeof(broadcast_address)); sizeof(broadcast_address));
if (strip_info->manual_dev_addr) if (strip_info->manual_dev_addr)
*(MetricomAddress *) strip_info->dev.dev_addr = *addr; *(MetricomAddress *) strip_info->dev->dev_addr = *addr;
else else
*(MetricomAddress *) strip_info->dev.dev_addr = *(MetricomAddress *) strip_info->dev->dev_addr =
strip_info->true_dev_addr; strip_info->true_dev_addr;
return 0; return 0;
} }
...@@ -2496,7 +2496,7 @@ static int strip_open_low(struct net_device *dev) ...@@ -2496,7 +2496,7 @@ static int strip_open_low(struct net_device *dev)
strip_info->user_baud = get_baud(strip_info->tty); strip_info->user_baud = get_baud(strip_info->tty);
printk(KERN_INFO "%s: Initializing Radio.\n", printk(KERN_INFO "%s: Initializing Radio.\n",
strip_info->dev.name); strip_info->dev->name);
ResetRadio(strip_info); ResetRadio(strip_info);
strip_info->idle_timer.expires = jiffies + 1 * HZ; strip_info->idle_timer.expires = jiffies + 1 * HZ;
add_timer(&strip_info->idle_timer); add_timer(&strip_info->idle_timer);
...@@ -2589,6 +2589,8 @@ static void strip_free(struct strip *strip_info) ...@@ -2589,6 +2589,8 @@ static void strip_free(struct strip *strip_info)
if (strip_info->next) if (strip_info->next)
strip_info->next->referrer = strip_info->referrer; strip_info->next->referrer = strip_info->referrer;
strip_info->magic = 0; strip_info->magic = 0;
if (strip_info->dev)
kfree(strip_info->dev);
kfree(strip_info); kfree(strip_info);
} }
...@@ -2600,6 +2602,7 @@ static struct strip *strip_alloc(void) ...@@ -2600,6 +2602,7 @@ static struct strip *strip_alloc(void)
{ {
int channel_id = 0; int channel_id = 0;
struct strip **s = &struct_strip_list; struct strip **s = &struct_strip_list;
struct net_device *dev;
struct strip *strip_info = (struct strip *) struct strip *strip_info = (struct strip *)
kmalloc(sizeof(struct strip), GFP_KERNEL); kmalloc(sizeof(struct strip), GFP_KERNEL);
...@@ -2612,13 +2615,22 @@ static struct strip *strip_alloc(void) ...@@ -2612,13 +2615,22 @@ static struct strip *strip_alloc(void)
memset(strip_info, 0, sizeof(struct strip)); memset(strip_info, 0, sizeof(struct strip));
/* allocate the net_device */
dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
if (!dev) {
kfree(strip_info);
return NULL;
}
strip_info->dev = dev;
SET_MODULE_OWNER(dev);
/* /*
* Search the list to find where to put our new entry * Search the list to find where to put our new entry
* (and in the process decide what channel number it is * (and in the process decide what channel number it is
* going to be) * going to be)
*/ */
while (*s && (*s)->dev.base_addr == channel_id) { while (*s && (*s)->dev->base_addr == channel_id) {
channel_id++; channel_id++;
s = &(*s)->next; s = &(*s)->next;
} }
...@@ -2639,15 +2651,15 @@ static struct strip *strip_alloc(void) ...@@ -2639,15 +2651,15 @@ static struct strip *strip_alloc(void)
strip_info->gratuitous_arp = jiffies + LongTime; strip_info->gratuitous_arp = jiffies + LongTime;
strip_info->arp_interval = 0; strip_info->arp_interval = 0;
init_timer(&strip_info->idle_timer); init_timer(&strip_info->idle_timer);
strip_info->idle_timer.data = (long) &strip_info->dev; strip_info->idle_timer.data = (long) dev;
strip_info->idle_timer.function = strip_IdleTask; strip_info->idle_timer.function = strip_IdleTask;
/* Note: strip_info->if_name is currently 8 characters long */ /* Note: strip_info->if_name is currently 8 characters long */
sprintf(strip_info->dev.name, "st%d", channel_id); sprintf(dev->name, "st%d", channel_id);
strip_info->dev.base_addr = channel_id; dev->base_addr = channel_id;
strip_info->dev.priv = (void *) strip_info; dev->priv = (void *) strip_info;
strip_info->dev.next = NULL; dev->next = NULL;
strip_info->dev.init = strip_dev_init; dev->init = strip_dev_init;
return strip_info; return strip_info;
} }
...@@ -2682,7 +2694,7 @@ static int strip_open(struct tty_struct *tty) ...@@ -2682,7 +2694,7 @@ static int strip_open(struct tty_struct *tty)
* strip_dev_init() will be called as a side-effect * strip_dev_init() will be called as a side-effect
*/ */
if (register_netdev(&strip_info->dev) != 0) { if (register_netdev(strip_info->dev) != 0) {
printk(KERN_ERR "strip: register_netdev() failed.\n"); printk(KERN_ERR "strip: register_netdev() failed.\n");
strip_free(strip_info); strip_free(strip_info);
return -ENFILE; return -ENFILE;
...@@ -2699,7 +2711,7 @@ static int strip_open(struct tty_struct *tty) ...@@ -2699,7 +2711,7 @@ static int strip_open(struct tty_struct *tty)
* Restore default settings * Restore default settings
*/ */
strip_info->dev.type = ARPHRD_METRICOM; /* dtang */ strip_info->dev->type = ARPHRD_METRICOM; /* dtang */
/* /*
* Set tty options * Set tty options
...@@ -2709,15 +2721,13 @@ static int strip_open(struct tty_struct *tty) ...@@ -2709,15 +2721,13 @@ static int strip_open(struct tty_struct *tty)
tty->termios->c_cflag |= CLOCAL; /* Ignore modem control signals. */ tty->termios->c_cflag |= CLOCAL; /* Ignore modem control signals. */
tty->termios->c_cflag &= ~HUPCL; /* Don't close on hup */ tty->termios->c_cflag &= ~HUPCL; /* Don't close on hup */
MOD_INC_USE_COUNT;
printk(KERN_INFO "STRIP: device \"%s\" activated\n", printk(KERN_INFO "STRIP: device \"%s\" activated\n",
strip_info->dev.name); strip_info->dev->name);
/* /*
* Done. We have linked the TTY line to a channel. * Done. We have linked the TTY line to a channel.
*/ */
return (strip_info->dev.base_addr); return (strip_info->dev->base_addr);
} }
/* /*
...@@ -2738,15 +2748,14 @@ static void strip_close(struct tty_struct *tty) ...@@ -2738,15 +2748,14 @@ static void strip_close(struct tty_struct *tty)
if (!strip_info || strip_info->magic != STRIP_MAGIC) if (!strip_info || strip_info->magic != STRIP_MAGIC)
return; return;
unregister_netdev(&strip_info->dev); unregister_netdev(strip_info->dev);
tty->disc_data = 0; tty->disc_data = 0;
strip_info->tty = NULL; strip_info->tty = NULL;
printk(KERN_INFO "STRIP: device \"%s\" closed down\n", printk(KERN_INFO "STRIP: device \"%s\" closed down\n",
strip_info->dev.name); strip_info->dev->name);
strip_free(strip_info); strip_free(strip_info);
tty->disc_data = NULL; tty->disc_data = NULL;
MOD_DEC_USE_COUNT;
} }
...@@ -2767,13 +2776,13 @@ static int strip_ioctl(struct tty_struct *tty, struct file *file, ...@@ -2767,13 +2776,13 @@ static int strip_ioctl(struct tty_struct *tty, struct file *file,
switch (cmd) { switch (cmd) {
case SIOCGIFNAME: case SIOCGIFNAME:
if(copy_to_user((void *) arg, strip_info->dev.name, strlen(strip_info->dev.name) + 1)) if(copy_to_user((void *) arg, strip_info->dev->name, strlen(strip_info->dev->name) + 1))
return -EFAULT; return -EFAULT;
break; break;
case SIOCSIFHWADDR: case SIOCSIFHWADDR:
{ {
MetricomAddress addr; MetricomAddress addr;
//printk(KERN_INFO "%s: SIOCSIFHWADDR\n", strip_info->dev.name); //printk(KERN_INFO "%s: SIOCSIFHWADDR\n", strip_info->dev->name);
if(copy_from_user(&addr, (void *) arg, sizeof(MetricomAddress))) if(copy_from_user(&addr, (void *) arg, sizeof(MetricomAddress)))
return -EFAULT; return -EFAULT;
return set_mac_address(strip_info, &addr); return set_mac_address(strip_info, &addr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment