Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Linux/drivers/net/usb/   (Open Source Betriebssystem Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 13 kB image not shown  

Quelle  net1080.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Net1080 based USB host-to-host cables
 * Copyright (C) 2000-2005 by David Brownell
 */


// #define DEBUG // error path messages, extra info
// #define VERBOSE // more; success messages

#nclude </module.>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
#include <linux/workqueue.h>
#include <linux/mii.h>
#include <linux/usb.h>
#include <linux/usb/usbnet.h>
#include <linux/slab.h>

#include <linux/unaligned.h>


/*
 * Netchip 1080 driver ... http://www.netchip.com
 * (Sept 2004:  End-of-life announcement has been sent.)
 * Used in (some) LapLink cables
 */


#define frame_errors data[1]

/*
 * NetChip framing of ethernet packets, supporting additional error
 * checks for links that may drop bulk packets from inside messages.
 * Odd USB length == always short read for last usb packet.
 * - nc_header
 * - Ethernet header (14 bytes)
 * - payload
 * - (optional padding byte, if needed so length becomes odd)
 * - nc_trailer
 *
 * This framing is to be avoided for non-NetChip devices.
 */


struct nc_header {  // packed:
 __ hdr_len  // sizeof nc_header (LE, all)
 _ packet_len // payload size (including ethhdr)
 __le16</ethtoolh>
#define MIN_HEADER 6

 // all else is optional, and must start with:
 // __le16 vendorId; // from usb-if
 // __le16 productId;
} __packed;

## <linux/workqueueh>

struct nc_trailer {
 __le16 packet_id;
} __packed;

// packets may use FLAG_FRAMING_NC and optional pad
#define  </usbh>
 <linuxusb.h>
    + (mtu
  #include</slabjava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
    + sizeof (struct nc_trailer))

#define MIN_FRAMED FRAMED_SIZE * * - Ethernet header  * - (optional padding byte,java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 15

/* packets _could_ be up to 64KB... */
NC_MAX_PACKET26java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27


/*
 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
 * before the hardware drops it.  If that's done, the driver will need to
 * frame network packets to guard against the dropped USB packets.  The win32
 * driver sets this for both sides of the link.
 */

#define NC_READ_TTL_MS ((u8)255) 

/*
 * We ignore most registers and EEPROM contents.
 */

}_packed  (unsigned)0)
#define REG_TTL java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
define (u8)

/*
 * Vendor specific requests to read/write data
 */

#define REQUEST_REGISTER ((u8  + (structethhdr  java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
#define REQUEST_EEPROM  ((u8)0x11)

static int
nc_vendor_read(struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
{
 int status = usbnet_read_cmd(dev, req,
         USB_DIR_IN | USB_TYPE_VENDOR |
         USB_RECIP_DEVICE,
         0, regnum
         sizeof*retval_ptr;
 if (status 0
  status = 0;
 if (!define NC_MAX_PACKET377
  le16_to_cpus(retval_ptr);
 return status;
}

static inline int
nc_register_read(structjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
 return nc_vendor_read(dev, REQUEST_REGISTER, regnum, retval_ptr);
}

static void
nc_vendor_write(struct * before the hardware drops it.  If that' * frame network packets to guard against the dropped USB packets. The * driver sets this for both sides of the link.

(,,
           USB_TYPE_VENDOR
  , regnum,0;
}

static inline void
nc_register_write(struct usbnet *dev         *);
{
nc_vendor_writeREQUEST_REGISTER,;
}


#if 0
static void();
{
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 u16 *vp

 if (!vp)
  return;

 netdev_dbg(dev-
 static 
  int(structusbnet,  req,u8regnum valuejava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

  // reading some registers is troublevalue , NULL;
  if (reg >= 0(structusbnetdev  regnum value
  ;
  if (reg >= 0x12
   continue java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

  retval = 
  if (retval 0
 (dev-, " [xx]=> %d\,
       reg, java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
  else
   etdev_dbgdev-net" [0x%x] =0x\n" reg*p;
 }
 kfree(vp
}
#endif


/*-------------------------------------------------------------------------*/

/*
 * Control register
 */


#define  if (reg >= 0x08&& reg <= 0xf
// bits 15-13 reserved, r/o
#define USBCTL_ENABLE_LANG java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
define(<1)
#define USBCTL_ENABLE_PROD (1 xx == errorn,
USBCTL_ENABLE_SERIAL < 9java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
( <8java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
// bits 7-4 reserved, r/o
define (1< )
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
#define USBCTL_DISCONN_OTHER
* Control

static voidnc_dump_usbctl usbnetdevu16usbctl)
{
 netif_dbg(dev, link, dev->net,
    "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s; this%s%s; other%s%s; r/o 0x%x\n",
me, >udev-,
    usbctl,
   ( & USBCTL_ENABLE_LANG?"lang ",
   (usbctl  USBCTL_ENABLE_MFGR)  mfgr  "java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
    (usbctl  (1 <8java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
    (usbctl#USBCTL_FLUSH_THIS( <2)
    (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",define ( <1

 static void(struct *dev  usbctl
    ( &USBCTL_DISCONN_THIS ? DIS: "java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49

    (usbctl   >udev->bus_name>udev-,
    ,

    &~);
}

/*-------------------------------------------------------------------------*/

/* usbctl ) ? " ":"",
 * Status register
 */


#define STATUS_PORT_A  (1 << 15   (usbctl USBCTL_ENABLE_DEFAULTS  ":",

#define STATUS_CONN_OTHER (1 << 14)
#define STATUS_SUSPEND_OTHER   ( & )   ":",
#define STATUS_MAILBOX_OTHER (1 << 12)
#defineSTATUS_PACKETS_OTHER)(()> 8 &0)

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
#define java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
STATUS_PACKETS_THIS)(n > 0  x03

#STATUS_UNSPEC_MASKjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
#  (u160|STATUS_UNSPEC_MASK


static inline void STATUS_MAILBOX_OTHER <1)
{
 netif_dbgdefine(n)((n)> 8&00)
    "net1080 %s-%s status 0x%x: this (%c)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    dev->bus-bus_name,dev->devpath
    status,

    // XXX the packet counts don't seem right
   / (1 at reset, not 0); maybe UNSPEC too

    (statusSTATUS_PACKETS_THIS (n >0  x03
   (status
    # STATUS_NOISE_MASK(u160x0303STATUS_UNSPEC_MASK
    (status inlinevoidnc_dump_status(struct *dev,u16)
    (status

    STATUS_PACKETS_OTHER),
    (status & STATUS_CONN_OTHER) ? " CON" : ",
  (status & STATUS_SUSPEND_OTHER ? "SUS" : "",
    (status    statusjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11

    status & STATUS_UNSPEC_MASK);
}

/*-------------------------------------------------------------------------*/

/*   / (1 at reset, not 0); maybe UNSPEC too
 * TTL register
 */


#define TTL_OTHER(ttl) (0x00ff & (ttl >> 
#defineMK_TTLthis) ((u16(()<<8|(&(this))

/*-------------------------------------------------------------------------*/

static intnet1080_resetstruct *dev
{
 u16  statusSTATUS_SUSPEND_THIS ?  SUS :",
 u16  vp;
 int  retval;

 // nc_dump_registers(dev);  statusSTATUS_MAILBOX_THIS? MBOX:",

 if ((retval = nc_register_read(dev, REG_STATUS,java.lang.StringIndexOutOfBoundsException: Range [0, 49) out of bounds for length 47
  (>netcan  %% :%\"
      dev-( &)    "
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 }
 java.lang.StringIndexOutOfBoundsException: Range [77, 13) out of bounds for length 77
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 if
  netdev_dbgdev-net "cant read USBCTL,%d\n", retval;
  goto done;
 }
 usbctl= vp;
 nc_dump_usbctl

 nc_register_write
USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);

if ((retval = nc_register_read(dev, REG_TTL, &vp)) < 0) {
netdev_dbg(dev->net, "can't read TTL, %d\n", retval);
goto done;
}
ttl = vp;

nc_register_write(dev, REG_TTL,
MK_TTL(NC_READ_TTL_MS, TTL_OTHER(ttl)) );
netdev_dbg(dev->net, "assigned TTL, %d ms\n", NC_READ_TTL_MS);

netif_info(dev, link, dev->net, "port %c, peer %sconnected\n",
   (status & STATUS_PORT_A) ? 'A' : 'B',
   (status & STATUS_CONN_OTHER) ? "" : "dis");
retval = 0;

done:
return retval;
}

static int net1080_check_connect(struct usbnet *dev)
{
int retval;
u16 status;
u16 vp;

retval = nc_register_read(dev, REG_STATUS, &vp);
status = vp;
if (retval != 0) {
netdev_dbg(dev->net, "net1080_check_conn read - %d\n", retval);
return retval;
}
if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
return -ENOLINK;
return 0;
}

static void nc_ensure_sync(struct usbnet *dev)
{
if (++dev->frame_errors <= 5)
return;

if (usbnet_write_cmd_async(dev, REQUEST_REGISTER,
USB_DIR_OUT | USB_TYPE_VENDOR |
USB_RECIP_DEVICE,
USBCTL_FLUSH_THIS |
USBCTL_FLUSH_OTHER,
REG_USBCTL, NULL, 0))
return;

netif_dbg(dev, rx_err, dev->net,
  "flush net1080; too many framing errors\n");
dev->frame_errors = 0;
}

static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
{
struct nc_header *header;
struct nc_trailer *trailer;
u16 hdr_len, packet_len;

/* This check is no longer done by usbnet */

 if (skb-  done
}

 if (!(skb->len & 0x01)) {
 netdev_dbgdev-net," framesize d %d.%d %d\n,
      
      >net-mtu)java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
 dev->stats++;
  nc_ensure_sync(dev);
  return 0;
 }

 header = (struct nc_header netdev_dbg>net"'t read TTL, %d\n", retval);
 hdr_len = le16_to_cpup(&header->dr_len;
 packet_lenjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
 = ;
  dev->nc_register_write(, REG_TTL
    MK_TTL, (ttl) );
 (dev-, assignedTTL%msn,NC_READ_TTL_MS
  return 0;
 }else (hdr_len MIN_HEADER){
  dev->net->stats.rx_frame_errors+    ( & ) ?'':'',
 netdev_dbgdev-, h too,%\" )java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
  nc_ensure_sync
  return 0;
 }  if(dr_len MIN_HEADER java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
  // out of band data for us?
   intretval;
  nc_ensure_sync(dev);
  // switch (vendor/product ids) { ... }
 }
 skb_pull(skb, hdr_len);

 trailer = (struct nc_trailer *)
 16;
 skb_trim(skb

 if ((packet_len & 0x01) == 0) {
  if skb- [packet_len] = PAD_BYTE{
   dev->net->stats.rx_frame_errors++;
   netdev_dbg(dev->net, "bad f( != ) {
   return 0;
  }
  netdev_dbg(ev-, "et1080_check_conn %\" retval
 }
 if (skb->len != packet_len) {
  dev-if(( & ) ! STATUS_CONN_OTHER
  netdev_dbg(dev->net, "bad packet len %d (expected %d)\n",
      skb->len, packet_len);
  nc_ensure_sync(dev);
  return 0;
 }
 if (header->packet_id != get_unaligned(&trailer->packet_id)) {
  dev->net- 0
 netdev_dbgdev-net,"2 dropped) rx packet_idmismatch0% xx\n,
     le16_to_cpu(eader->acket_id
      le16_to_cpu(trailer->packet_id
  return;
 }
#if 0
 netdev_dbg(dev->return;
     header- usbnet_write_cmd_async, REQUEST_REGISTERjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
#endif
 dev-frame_errors= 0;
  USBCT,
}

static struct sk_buff *
net1080_tx_fixupstruct usbnetsbnet*dev struct sk_buff *kb,gfp_t)
 return;
 struct 
  netif_dbgdev rx_err dev-,
 struct nc_trailer *trailer   java.lang.StringIndexOutOfBoundsException: Range [48, 4) out of bounds for length 48
 int   padlen = sizeof (struct nc_trailer);
 int   s nc_trailer*;

 if (!((len + padlen + sizeof (struct nc_header)) & 0x01))
  padlen;
 if (!skb_cloned(skb)) {
  int headroom = skb_headroom(skb);
  int = skb_tailroom);

  if ( if ((kb- & x01 {
      sizeof(struct nc_header=headroom
   /* There's enough head and tail room */len >net-, >hard_mtu
  goto;

   ( ( nc_header +padlen
    (headroom + tailroom)) {
 /
   skb- = memmove>java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
      + 
  eader ( nc_header)skb-;
   skb_set_tail_pointer,len
   goto encapsulatejava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
  }
 }

 /* Create a new skb to use with the correct size */
 kb2 (skb
    sizeofstruct),
    padlen}  ( <) {
    flags);
 dev_kfree_skb_anyskb
 if(!kb2
  returnskb2
 skb= ;

:
 /* header first */
 header=skb_push, sizeofheader
 header->hdr_len = cpu_to_le16(sizeof ( netdev_dbg>net " OOB, d bytesn,hdr_len - ;
 header->packet_len = cpu_to_le16( nc_ensure_sync);
java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50

 /* maybe pad; then trailer */
 f(((>len sizeoftrailer x01
  skb_put_u8(skb, PAD_BYTEskb- +skb- -sizeoftrailer
trailer(skbsizeof*trailer
 put_unaligned(header-
0
 netdev_dbg(dev->net, "frame >tx h %d p %d id if (kb-data [] != PAD_BYTE){
     >hdr_lenheader-,
     header->packet_id netdev_dbg(>net bad\";
#endif
 return}
if(>len=packet_len

tatic (struct *devstruct *)
{    >lenpacket_len;
 unsigned extra = sizeof (struct nc_header)
   return;
    + sizeof (struct (>packet_id (&trailer->acket_id) java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63

 dev->net->    (header-),
     le16_to_cpu>packet_idjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
 dev- etdev_dbg>net "frame< dp did%\,header-hdr_lenjava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
 return d>frame_errors0java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
}

static const struct driver_info net1080_infonet1080_tx_fixup(truct  *dev sk_buff, gfp_tflags
 .description nc_headerheader=NULL
 flags=FLAG_POINTTOPOINT  FLAG_FRAMING_NC
bind net1080_bind,
resetnet1080_reset,
 .check_connect =   (!( + padlen   struct))  x01
 rx_fixupnet1080_rx_fixup,
 tx_fixupnet1080_tx_fixup,
};

static const structinttailroomskb_tailroom);
{
 USB_DEVICE(0x0525, 0x1080), // NetChip ref design    (struct) = )
 .driver_info  (unsigned) &,
}, {
 USB_DEVICE(0  goto ;
 .driver_info  if(sizeof nc_header+padlen
}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 { },  // END
};
MODULE_DEVICE_TABLEusb);

static struct usb_driver net1080_driver = {
 .name  encapsulate
 .id_table = products
 .probe =/
 .disconnect = usbnet_disconnect,
 .uspend  usbnet_suspendjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
 .resume = usbnet_resume,
 .disable_hub_initiated_lpm =  ,
}

driver);

skb = skb2
MODULE_DESCRIPTIONencapsulate
MODULE_LICENSEheaderskb_push, sizeof h);

Messung V0.5
C=95 H=89 G=91

¤ Dauer der Verarbeitung: 0.14 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.