0001
0002 #ifndef _FIREWIRE_FWSERIAL_H
0003 #define _FIREWIRE_FWSERIAL_H
0004
0005 #include <linux/kernel.h>
0006 #include <linux/tty.h>
0007 #include <linux/tty_driver.h>
0008 #include <linux/tty_flip.h>
0009 #include <linux/list.h>
0010 #include <linux/firewire.h>
0011 #include <linux/firewire-constants.h>
0012 #include <linux/spinlock.h>
0013 #include <linux/rcupdate.h>
0014 #include <linux/mutex.h>
0015 #include <linux/serial.h>
0016 #include <linux/serial_reg.h>
0017 #include <linux/module.h>
0018 #include <linux/seq_file.h>
0019 #include <linux/debugfs.h>
0020
0021 #include "dma_fifo.h"
0022
0023 #ifdef FWTTY_PROFILING
0024 #define DISTRIBUTION_MAX_SIZE 8192
0025 #define DISTRIBUTION_MAX_INDEX (ilog2(DISTRIBUTION_MAX_SIZE) + 1)
0026 static inline void fwtty_profile_data(unsigned int stat[], unsigned int val)
0027 {
0028 int n = (val) ? min(ilog2(val) + 1, DISTRIBUTION_MAX_INDEX) : 0;
0029 ++stat[n];
0030 }
0031 #else
0032 #define DISTRIBUTION_MAX_INDEX 0
0033 #define fwtty_profile_data(st, n)
0034 #endif
0035
0036
0037 struct virt_plug_params {
0038 __be32 status_hi;
0039 __be32 status_lo;
0040 __be32 fifo_hi;
0041 __be32 fifo_lo;
0042 __be32 fifo_len;
0043 };
0044
0045 struct peer_work_params {
0046 union {
0047 struct virt_plug_params plug_req;
0048 };
0049 };
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 struct fwtty_peer {
0077 struct fw_unit *unit;
0078 struct fw_serial *serial;
0079 u64 guid;
0080 int generation;
0081 int node_id;
0082 unsigned int speed;
0083 int max_payload;
0084 u64 mgmt_addr;
0085
0086
0087 u64 status_addr;
0088 u64 fifo_addr;
0089 int fifo_len;
0090
0091 struct list_head list;
0092 struct rcu_head rcu;
0093
0094 spinlock_t lock;
0095 work_func_t workfn;
0096 struct work_struct work;
0097 struct peer_work_params work_params;
0098 struct timer_list timer;
0099 int state;
0100 struct delayed_work connect;
0101 int connect_retries;
0102
0103 struct fwtty_port *port;
0104 };
0105
0106 #define to_peer(ptr, field) (container_of(ptr, struct fwtty_peer, field))
0107
0108
0109 enum fwtty_peer_state {
0110 FWPS_GONE,
0111 FWPS_NOT_ATTACHED,
0112 FWPS_ATTACHED,
0113 FWPS_PLUG_PENDING,
0114 FWPS_PLUG_RESPONDING,
0115 FWPS_UNPLUG_PENDING,
0116 FWPS_UNPLUG_RESPONDING,
0117
0118 FWPS_NO_MGMT_ADDR = -1,
0119 };
0120
0121 #define CONNECT_RETRY_DELAY HZ
0122 #define MAX_CONNECT_RETRIES 10
0123
0124
0125 static inline void peer_set_state(struct fwtty_peer *peer, int new)
0126 {
0127 peer->state = new;
0128 }
0129
0130 static inline struct fwtty_port *peer_revert_state(struct fwtty_peer *peer)
0131 {
0132 struct fwtty_port *port = peer->port;
0133
0134 peer->port = NULL;
0135 peer_set_state(peer, FWPS_NOT_ATTACHED);
0136 return port;
0137 }
0138
0139 struct fwserial_mgmt_pkt {
0140 struct {
0141 __be16 len;
0142 __be16 code;
0143 } hdr;
0144 union {
0145 struct virt_plug_params plug_req;
0146 struct virt_plug_params plug_rsp;
0147 };
0148 } __packed;
0149
0150
0151 #define FWSC_RSP_OK 0x0000
0152 #define FWSC_RSP_NACK 0x8000
0153 #define FWSC_CODE_MASK 0x0fff
0154
0155 #define FWSC_VIRT_CABLE_PLUG 1
0156 #define FWSC_VIRT_CABLE_UNPLUG 2
0157 #define FWSC_VIRT_CABLE_PLUG_RSP 3
0158 #define FWSC_VIRT_CABLE_UNPLUG_RSP 4
0159
0160
0161 #define VIRT_CABLE_PLUG_TIMEOUT (60 * HZ)
0162
0163 struct stats {
0164 unsigned int xchars;
0165 unsigned int dropped;
0166 unsigned int tx_stall;
0167 unsigned int fifo_errs;
0168 unsigned int sent;
0169 unsigned int lost;
0170 unsigned int throttled;
0171 unsigned int reads[DISTRIBUTION_MAX_INDEX + 1];
0172 unsigned int writes[DISTRIBUTION_MAX_INDEX + 1];
0173 unsigned int txns[DISTRIBUTION_MAX_INDEX + 1];
0174 unsigned int unthrottle[DISTRIBUTION_MAX_INDEX + 1];
0175 };
0176
0177 struct fwconsole_ops {
0178 void (*notify)(int code, void *data);
0179 void (*stats)(struct stats *stats, void *data);
0180 void (*proc_show)(struct seq_file *m, void *data);
0181 };
0182
0183
0184 #define FWCON_NOTIFY_ATTACH 1
0185 #define FWCON_NOTIFY_DETACH 2
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238 struct fwtty_port {
0239 struct tty_port port;
0240 struct device *device;
0241 unsigned int index;
0242 struct fw_serial *serial;
0243 struct fw_address_handler rx_handler;
0244
0245 struct fwconsole_ops *fwcon_ops;
0246 void *con_data;
0247
0248 wait_queue_head_t wait_tx;
0249 struct delayed_work emit_breaks;
0250 unsigned int cps;
0251 unsigned long break_last;
0252
0253 struct work_struct hangup;
0254
0255 unsigned int mstatus;
0256
0257 spinlock_t lock;
0258 unsigned int mctrl;
0259 struct delayed_work drain;
0260 struct dma_fifo tx_fifo;
0261 int max_payload;
0262 unsigned int status_mask;
0263 unsigned int ignore_mask;
0264 unsigned int break_ctl:1,
0265 write_only:1,
0266 overrun:1,
0267 loopback:1;
0268 unsigned long flags;
0269
0270 struct fwtty_peer __rcu *peer;
0271
0272 struct async_icount icount;
0273 struct stats stats;
0274 };
0275
0276 #define to_port(ptr, field) (container_of(ptr, struct fwtty_port, field))
0277
0278
0279 #define IN_TX 0
0280 #define STOP_TX 1
0281
0282
0283 #define OOB_RX_THROTTLE 0x00010000
0284 #define MCTRL_RSRVD 0x000e0000
0285 #define OOB_TX_THROTTLE 0x00100000
0286 #define MSTATUS_RSRVD 0x00e00000
0287
0288 #define MCTRL_MASK (TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | TIOCM_OUT2 | \
0289 TIOCM_LOOP | OOB_RX_THROTTLE | MCTRL_RSRVD)
0290
0291
0292
0293 #define FREQ_BREAKS (HZ / 50)
0294
0295
0296 #define MAX_CARD_PORTS CONFIG_FWTTY_MAX_CARD_PORTS
0297 #define MAX_TOTAL_PORTS CONFIG_FWTTY_MAX_TOTAL_PORTS
0298
0299
0300 #define FWTTY_PORT_TXFIFO_LEN 4096
0301 #define FWTTY_PORT_MAX_PEND_DMA 8
0302 #define DRAIN_THRESHOLD 1024
0303 #define MAX_ASYNC_PAYLOAD 4096
0304 #define WRITER_MINIMUM 128
0305
0306 #define HIGH_WATERMARK 32768
0307
0308
0309
0310
0311
0312 #define FWTTY_PORT_RXFIFO_LEN MAX_ASYNC_PAYLOAD
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324 struct fw_serial {
0325 struct fw_card *card;
0326 struct kref kref;
0327
0328 struct dentry *debugfs;
0329 struct fwtty_peer *self;
0330
0331 struct list_head list;
0332 struct list_head peer_list;
0333
0334 struct fwtty_port *ports[MAX_CARD_PORTS];
0335 };
0336
0337 #define to_serial(ptr, field) (container_of(ptr, struct fw_serial, field))
0338
0339 #define TTY_DEV_NAME "fwtty"
0340 static const char tty_dev_name[] = TTY_DEV_NAME;
0341 static const char loop_dev_name[] = "fwloop";
0342
0343 extern struct tty_driver *fwtty_driver;
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353 static inline int link_speed_to_max_payload(unsigned int speed)
0354 {
0355
0356 return min(512 << speed, 4096);
0357 }
0358
0359 #endif