0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef _AP_BUS_H_
0014 #define _AP_BUS_H_
0015
0016 #include <linux/device.h>
0017 #include <linux/types.h>
0018 #include <linux/hashtable.h>
0019 #include <asm/isc.h>
0020 #include <asm/ap.h>
0021
0022 #define AP_DEVICES 256
0023 #define AP_DOMAINS 256
0024 #define AP_IOCTLS 256
0025 #define AP_RESET_TIMEOUT (HZ*0.7)
0026 #define AP_CONFIG_TIME 30
0027 #define AP_POLL_TIME 1
0028 #define AP_DEFAULT_MAX_MSG_SIZE (12 * 1024)
0029 #define AP_TAPQ_ML_FIELD_CHUNK_SIZE (4096)
0030
0031 extern int ap_domain_index;
0032 extern atomic_t ap_max_msg_size;
0033
0034 extern DECLARE_HASHTABLE(ap_queues, 8);
0035 extern spinlock_t ap_queues_lock;
0036
0037 static inline int ap_test_bit(unsigned int *ptr, unsigned int nr)
0038 {
0039 return (*ptr & (0x80000000u >> nr)) != 0;
0040 }
0041
0042 #define AP_RESPONSE_NORMAL 0x00
0043 #define AP_RESPONSE_Q_NOT_AVAIL 0x01
0044 #define AP_RESPONSE_RESET_IN_PROGRESS 0x02
0045 #define AP_RESPONSE_DECONFIGURED 0x03
0046 #define AP_RESPONSE_CHECKSTOPPED 0x04
0047 #define AP_RESPONSE_BUSY 0x05
0048 #define AP_RESPONSE_INVALID_ADDRESS 0x06
0049 #define AP_RESPONSE_OTHERWISE_CHANGED 0x07
0050 #define AP_RESPONSE_INVALID_GISA 0x08
0051 #define AP_RESPONSE_Q_FULL 0x10
0052 #define AP_RESPONSE_NO_PENDING_REPLY 0x10
0053 #define AP_RESPONSE_INDEX_TOO_BIG 0x11
0054 #define AP_RESPONSE_NO_FIRST_PART 0x13
0055 #define AP_RESPONSE_MESSAGE_TOO_BIG 0x15
0056 #define AP_RESPONSE_REQ_FAC_NOT_INST 0x16
0057 #define AP_RESPONSE_INVALID_DOMAIN 0x42
0058
0059
0060
0061
0062 #define AP_DEVICE_TYPE_PCICC 3
0063 #define AP_DEVICE_TYPE_PCICA 4
0064 #define AP_DEVICE_TYPE_PCIXCC 5
0065 #define AP_DEVICE_TYPE_CEX2A 6
0066 #define AP_DEVICE_TYPE_CEX2C 7
0067 #define AP_DEVICE_TYPE_CEX3A 8
0068 #define AP_DEVICE_TYPE_CEX3C 9
0069 #define AP_DEVICE_TYPE_CEX4 10
0070 #define AP_DEVICE_TYPE_CEX5 11
0071 #define AP_DEVICE_TYPE_CEX6 12
0072 #define AP_DEVICE_TYPE_CEX7 13
0073 #define AP_DEVICE_TYPE_CEX8 14
0074
0075
0076
0077
0078 #define AP_FUNC_MEX4K 1
0079 #define AP_FUNC_CRT4K 2
0080 #define AP_FUNC_COPRO 3
0081 #define AP_FUNC_ACCEL 4
0082 #define AP_FUNC_EP11 5
0083 #define AP_FUNC_APXA 6
0084
0085
0086
0087
0088 enum ap_sm_state {
0089 AP_SM_STATE_RESET_START = 0,
0090 AP_SM_STATE_RESET_WAIT,
0091 AP_SM_STATE_SETIRQ_WAIT,
0092 AP_SM_STATE_IDLE,
0093 AP_SM_STATE_WORKING,
0094 AP_SM_STATE_QUEUE_FULL,
0095 NR_AP_SM_STATES
0096 };
0097
0098
0099
0100
0101 enum ap_sm_event {
0102 AP_SM_EVENT_POLL,
0103 AP_SM_EVENT_TIMEOUT,
0104 NR_AP_SM_EVENTS
0105 };
0106
0107
0108
0109
0110 enum ap_sm_wait {
0111 AP_SM_WAIT_AGAIN = 0,
0112 AP_SM_WAIT_TIMEOUT,
0113 AP_SM_WAIT_INTERRUPT,
0114 AP_SM_WAIT_NONE,
0115 NR_AP_SM_WAIT
0116 };
0117
0118
0119
0120
0121 enum ap_dev_state {
0122 AP_DEV_STATE_UNINITIATED = 0,
0123 AP_DEV_STATE_OPERATING,
0124 AP_DEV_STATE_SHUTDOWN,
0125 AP_DEV_STATE_ERROR,
0126 NR_AP_DEV_STATES
0127 };
0128
0129 struct ap_device;
0130 struct ap_message;
0131
0132
0133
0134
0135
0136
0137
0138 #define AP_DRIVER_FLAG_DEFAULT 0x0001
0139
0140 struct ap_driver {
0141 struct device_driver driver;
0142 struct ap_device_id *ids;
0143 unsigned int flags;
0144
0145 int (*probe)(struct ap_device *);
0146 void (*remove)(struct ap_device *);
0147 int (*in_use)(unsigned long *apm, unsigned long *aqm);
0148
0149
0150
0151
0152
0153
0154 void (*on_config_changed)(struct ap_config_info *new_config_info,
0155 struct ap_config_info *old_config_info);
0156
0157
0158
0159
0160
0161
0162 void (*on_scan_complete)(struct ap_config_info *new_config_info,
0163 struct ap_config_info *old_config_info);
0164 };
0165
0166 #define to_ap_drv(x) container_of((x), struct ap_driver, driver)
0167
0168 int ap_driver_register(struct ap_driver *, struct module *, char *);
0169 void ap_driver_unregister(struct ap_driver *);
0170
0171 struct ap_device {
0172 struct device device;
0173 int device_type;
0174 };
0175
0176 #define to_ap_dev(x) container_of((x), struct ap_device, device)
0177
0178 struct ap_card {
0179 struct ap_device ap_dev;
0180 int raw_hwtype;
0181 unsigned int functions;
0182 int queue_depth;
0183 int id;
0184 unsigned int maxmsgsize;
0185 bool config;
0186 bool chkstop;
0187 atomic64_t total_request_count;
0188 };
0189
0190 #define to_ap_card(x) container_of((x), struct ap_card, ap_dev.device)
0191
0192 struct ap_queue {
0193 struct ap_device ap_dev;
0194 struct hlist_node hnode;
0195 struct ap_card *card;
0196 spinlock_t lock;
0197 enum ap_dev_state dev_state;
0198 bool config;
0199 bool chkstop;
0200 ap_qid_t qid;
0201 bool interrupt;
0202 int queue_count;
0203 int pendingq_count;
0204 int requestq_count;
0205 u64 total_request_count;
0206 int request_timeout;
0207 struct timer_list timeout;
0208 struct list_head pendingq;
0209 struct list_head requestq;
0210 struct ap_message *reply;
0211 enum ap_sm_state sm_state;
0212 int last_err_rc;
0213 };
0214
0215 #define to_ap_queue(x) container_of((x), struct ap_queue, ap_dev.device)
0216
0217 typedef enum ap_sm_wait (ap_func_t)(struct ap_queue *queue);
0218
0219
0220 struct ap_fi {
0221 union {
0222 u16 cmd;
0223 struct {
0224 u8 flags;
0225 u8 action;
0226 };
0227 };
0228 };
0229
0230
0231 enum ap_fi_actions {
0232 AP_FI_ACTION_CCA_AGENT_FF = 0x01,
0233 AP_FI_ACTION_CCA_DOM_INVAL = 0x02,
0234 AP_FI_ACTION_NQAP_QID_INVAL = 0x03,
0235 };
0236
0237
0238 enum ap_fi_flags {
0239 AP_FI_FLAG_NO_RETRY = 0x01,
0240 AP_FI_FLAG_TOGGLE_SPECIAL = 0x02,
0241 };
0242
0243 struct ap_message {
0244 struct list_head list;
0245 unsigned long long psmid;
0246 void *msg;
0247 unsigned int len;
0248 unsigned int bufsize;
0249 u16 flags;
0250 struct ap_fi fi;
0251 int rc;
0252 void *private;
0253
0254 void (*receive)(struct ap_queue *, struct ap_message *,
0255 struct ap_message *);
0256 };
0257
0258 #define AP_MSG_FLAG_SPECIAL 0x0001
0259 #define AP_MSG_FLAG_USAGE 0x0002
0260 #define AP_MSG_FLAG_ADMIN 0x0004
0261
0262
0263
0264
0265
0266
0267 static inline void ap_init_message(struct ap_message *ap_msg)
0268 {
0269 memset(ap_msg, 0, sizeof(*ap_msg));
0270 }
0271
0272
0273
0274
0275
0276
0277 static inline void ap_release_message(struct ap_message *ap_msg)
0278 {
0279 kfree_sensitive(ap_msg->msg);
0280 kfree_sensitive(ap_msg->private);
0281 }
0282
0283
0284
0285
0286
0287
0288 int ap_send(ap_qid_t, unsigned long long, void *, size_t);
0289 int ap_recv(ap_qid_t, unsigned long long *, void *, size_t);
0290
0291 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event);
0292 enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event);
0293
0294 int ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg);
0295 void ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg);
0296 void ap_flush_queue(struct ap_queue *aq);
0297
0298 void *ap_airq_ptr(void);
0299 void ap_wait(enum ap_sm_wait wait);
0300 void ap_request_timeout(struct timer_list *t);
0301 void ap_bus_force_rescan(void);
0302
0303 int ap_test_config_usage_domain(unsigned int domain);
0304 int ap_test_config_ctrl_domain(unsigned int domain);
0305
0306 void ap_queue_init_reply(struct ap_queue *aq, struct ap_message *ap_msg);
0307 struct ap_queue *ap_queue_create(ap_qid_t qid, int device_type);
0308 void ap_queue_prepare_remove(struct ap_queue *aq);
0309 void ap_queue_remove(struct ap_queue *aq);
0310 void ap_queue_init_state(struct ap_queue *aq);
0311
0312 struct ap_card *ap_card_create(int id, int queue_depth, int raw_type,
0313 int comp_type, unsigned int functions, int ml);
0314
0315 #define APMASKSIZE (BITS_TO_LONGS(AP_DEVICES) * sizeof(unsigned long))
0316 #define AQMASKSIZE (BITS_TO_LONGS(AP_DOMAINS) * sizeof(unsigned long))
0317
0318 struct ap_perms {
0319 unsigned long ioctlm[BITS_TO_LONGS(AP_IOCTLS)];
0320 unsigned long apm[BITS_TO_LONGS(AP_DEVICES)];
0321 unsigned long aqm[BITS_TO_LONGS(AP_DOMAINS)];
0322 unsigned long adm[BITS_TO_LONGS(AP_DOMAINS)];
0323 };
0324
0325 extern struct ap_perms ap_perms;
0326 extern struct mutex ap_perms_mutex;
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336 struct ap_queue *ap_get_qdev(ap_qid_t qid);
0337
0338
0339
0340
0341
0342
0343
0344
0345 int ap_owned_by_def_drv(int card, int queue);
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358 int ap_apqn_in_matrix_owned_by_def_drv(unsigned long *apm,
0359 unsigned long *aqm);
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373 int ap_parse_mask_str(const char *str,
0374 unsigned long *bitmap, int bits,
0375 struct mutex *lock);
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387 int ap_wait_init_apqn_bindings_complete(unsigned long timeout);
0388
0389 void ap_send_config_uevent(struct ap_device *ap_dev, bool cfg);
0390 void ap_send_online_uevent(struct ap_device *ap_dev, int online);
0391
0392 #endif