Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
csr_wifi_hip_card_sdio.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  (c) Cambridge Silicon Radio Limited 2011
4  All rights reserved and confidential information of CSR
5 
6  Refer to LICENSE.txt included with this source for details
7  on the license terms.
8 
9 *****************************************************************************/
10 
11 /*
12  * ---------------------------------------------------------------------------
13  *
14  * FILE: csr_wifi_hip_card_sdio.h
15  *
16  * PURPOSE:
17  * Internal header for Card API for SDIO.
18  * ---------------------------------------------------------------------------
19  */
20 #ifndef __CARD_SDIO_H__
21 #define __CARD_SDIO_H__
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include "csr_wifi_hip_unifi.h"
28 #include "csr_wifi_hip_unifi_udi.h"
29 #include "csr_wifi_hip_unifihw.h"
31 #ifndef CSR_WIFI_HIP_TA_DISABLE
33 #endif
34 #include "csr_wifi_hip_xbv.h"
36 
37 
38 /*
39  *
40  * Configuration items.
41  * Which of these should go in a platform unifi_config.h file?
42  *
43  */
44 
45 /*
46  * When the traffic queues contain more signals than there is space for on
47  * UniFi, a limiting algorithm comes into play.
48  * If a traffic queue has enough slots free to buffer more traffic from the
49  * network stack, then the following check is applied. The number of free
50  * slots is RESUME_XMIT_THRESHOLD.
51  */
52 #define RESUME_XMIT_THRESHOLD 4
53 
54 
55 /*
56  * When reading signals from UniFi, the host processes pending all signals
57  * and then acknowledges them together in a single write to update the
58  * to-host-chunks-read location.
59  * When there is more than one bulk data transfer (e.g. one received data
60  * packet and a request for the payload data of a transmitted packet), the
61  * update can be delayed significantly. This ties up resources on chip.
62  *
63  * To remedy this problem, to-host-chunks-read is updated after processing
64  * a signal if TO_HOST_FLUSH_THRESHOLD bytes of bulk data have been
65  * transferred since the last update.
66  */
67 #define TO_HOST_FLUSH_THRESHOLD (500 * 5)
68 
69 
70 /* SDIO Card Common Control Registers */
71 #define SDIO_CCCR_SDIO_REVISION (0x00)
72 #define SDIO_SD_SPEC_REVISION (0x01)
73 #define SDIO_IO_ENABLE (0x02)
74 #define SDIO_IO_READY (0x03)
75 #define SDIO_INT_ENABLE (0x04)
76 #define SDIO_INT_PENDING (0x05)
77 #define SDIO_IO_ABORT (0x06)
78 #define SDIO_BUS_IFACE_CONTROL (0x07)
79 #define SDIO_CARD_CAPABILOTY (0x08)
80 #define SDIO_COMMON_CIS_POINTER (0x09)
81 #define SDIO_BUS_SUSPEND (0x0C)
82 #define SDIO_FUNCTION_SELECT (0x0D)
83 #define SDIO_EXEC_FLAGS (0x0E)
84 #define SDIO_READY_FLAGS (0x0F)
85 #define SDIO_FN0_BLOCK_SIZE (0x10)
86 #define SDIO_POWER_CONTROL (0x12)
87 #define SDIO_VENDOR_START (0xF0)
88 
89 #define SDIO_CSR_HOST_WAKEUP (0xf0)
90 #define SDIO_CSR_HOST_INT_CLEAR (0xf1)
91 #define SDIO_CSR_FROM_HOST_SCRATCH0 (0xf2)
92 #define SDIO_CSR_FROM_HOST_SCRATCH1 (0xf3)
93 #define SDIO_CSR_TO_HOST_SCRATCH0 (0xf4)
94 #define SDIO_CSR_TO_HOST_SCRATCH1 (0xf5)
95 #define SDIO_CSR_FUNC_EN (0xf6)
96 #define SDIO_CSR_CSPI_MODE (0xf7)
97 #define SDIO_CSR_CSPI_STATUS (0xf8)
98 #define SDIO_CSR_CSPI_PADDING (0xf9)
99 
100 
101 #define UNIFI_SD_INT_ENABLE_IENM 0x0001 /* Master INT Enable */
102 
103 #ifdef CSR_PRE_ALLOC_NET_DATA
104 #define BULK_DATA_PRE_ALLOC_NUM 16
105 #endif
106 
107 /*
108  * Structure to hold configuration information read from UniFi.
109  */
110 typedef struct
111 {
112  /*
113  * The version of the SDIO signal queues and bulk data pools
114  * configuration structure. The MSB is the major version number, used to
115  * indicate incompatible changes. The LSB gives the minor revision number,
116  * used to indicate changes that maintain backwards compatibility.
117  */
119 
120  /*
121  * offset from the start of the shared data memory to the SD IO
122  * control structure.
123  */
125 
126  /* Buffer handle of the from-host signal queue */
128 
129  /* Buffer handle of the to-host signal queue */
131 
132  /*
133  * Maximum number of signal primitive or bulk data command fragments that may be
134  * pending in the to-hw signal queue.
135  */
137 
138  /*
139  * Number of signal primitive or bulk data command fragments that must be pending
140  * in the to-host signal queue before the host will generate an interrupt
141  * to indicate that it has read a signal. This will usually be the total
142  * capacity of the to-host signal buffer less the size of the largest signal
143  * primitive divided by the signal primitive fragment size, but may be set
144  * to 1 to request interrupts every time that the host read a signal.
145  * Note that the hw may place more signals in the to-host signal queue
146  * than indicated by this field.
147  */
149 
150  /*
151  * Number of to-hw bulk data slots. Slots are numbered from 0 (zero) to
152  * one less than the value in this field
153  */
155 
156  /*
157  * Number of frm-hw bulk data slots. Slots are numbered from 0 (zero) to
158  * one less than the value in this field
159  */
161 
162  /*
163  * Size of the bulk data slots (2 octets)
164  * The size of the bulk data slots in octets. This will usually be
165  * the size of the largest MSDU. The value should always be even.
166  */
168 
169  /*
170  * Indicates that the host has finished the initialisation sequence.
171  * Initialised to 0x0000 by the firmware, and set to 0x0001 by us.
172  */
174 
175  /* Added by protocol version 0x0001 */
177 
178  /* Added by protocol version 0x0300 */
181 
182  /* Added by protocol version 0x0500 */
185 
186 /*
187  * These values may change with versions of the Host Interface Protocol.
188  */
189 /*
190  * Size of config info block pointed to by the CSR_SLT_SDIO_SLOT_CONFIG
191  * entry in the f/w symbol table
192  */
193 #define SDIO_CONFIG_DATA_SIZE 30
194 
195 /* Offset of the INIT flag in the config info block. */
196 #define SDIO_INIT_FLAG_OFFSET 0x12
197 #define SDIO_TO_HOST_SIG_PADDING_OFFSET 0x1C
198 
199 
200 /* Structure for a bulk data transfer command */
201 typedef struct
202 {
203  u16 cmd_and_len; /* bits 12-15 cmd, bits 0-11 len */
204  u16 data_slot; /* slot number, perhaps OR'd with SLOT_DIR_TO_HOST */
208 
209 
210 /* Bulk Data signal command values */
211 #define SDIO_CMD_SIGNAL 0x00
212 #define SDIO_CMD_TO_HOST_TRANSFER 0x01
213 #define SDIO_CMD_TO_HOST_TRANSFER_ACK 0x02 /*deprecated*/
214 #define SDIO_CMD_FROM_HOST_TRANSFER 0x03
215 #define SDIO_CMD_FROM_HOST_TRANSFER_ACK 0x04 /*deprecated*/
216 #define SDIO_CMD_CLEAR_SLOT 0x05
217 #define SDIO_CMD_OVERLAY_TRANSFER 0x06
218 #define SDIO_CMD_OVERLAY_TRANSFER_ACK 0x07 /*deprecated*/
219 #define SDIO_CMD_FROM_HOST_AND_CLEAR 0x08
220 #define SDIO_CMD_PADDING 0x0f
221 
222 #define SLOT_DIR_TO_HOST 0x8000
223 
224 
225 /* Initialise bulkdata slot
226  * params:
227  * bulk_data_desc_t *bulk_data_slot
228  */
229 #define UNIFI_INIT_BULK_DATA(bulk_data_slot) \
230  { \
231  (bulk_data_slot)->os_data_ptr = NULL; \
232  (bulk_data_slot)->data_length = 0; \
233  (bulk_data_slot)->os_net_buf_ptr = NULL; \
234  (bulk_data_slot)->net_buf_length = 0; \
235  }
236 
237 /*
238  * Structure to contain a SIGNAL datagram.
239  * This is used to build signal queues between the main driver and the
240  * i/o thread.
241  * The fields are:
242  * sigbuf Contains the HIP signal is wire-format (i.e. packed,
243  * little-endian)
244  * bulkdata Contains a copy of any associated bulk data
245  * signal_length The size of the signal in the sigbuf
246  */
247 typedef struct card_signal
248 {
250 
251  /* Length of the SIGNAL inside sigbuf */
253 
255 } card_signal_t;
256 
257 
258 /*
259  * Control structure for a generic ring buffer.
260  */
261 #define UNIFI_QUEUE_NAME_MAX_LENGTH 16
262 typedef struct
263 {
265 
266  /* Num elements in queue (capacity is one less than this!) */
268 
271 
273 } q_t;
274 
275 
276 #define UNIFI_RESERVED_COMMAND_SLOTS 2
277 
278 /* Considering approx 500 us per packet giving 0.5 secs */
279 #define UNIFI_PACKETS_INTERVAL 1000
280 
281 /*
282  * Dynamic slot reservation for QoS
283  */
284 typedef struct
285 {
286  u16 from_host_used_slots[UNIFI_NO_OF_TX_QS];
287  u16 from_host_max_slots[UNIFI_NO_OF_TX_QS];
288  u16 from_host_reserved_slots[UNIFI_NO_OF_TX_QS];
289 
290  /* Parameters to determine if a queue was active.
291  If number of packets sent is greater than the threshold
292  for the queue, the queue is considered active and no
293  re reservation is done, it is important not to keep this
294  value too low */
295  /* Packets sent during this interval */
296  u16 packets_txed[UNIFI_NO_OF_TX_QS];
298 
299  /* Number of packets to see if slots need to be reassigned */
301 
302  /* Once a queue reaches a stable state, avoid processing */
303  u8 queue_stable[UNIFI_NO_OF_TX_QS];
305 
306 
307 /* These are type-safe and don't write incorrect values to the
308  * structure. */
309 
310 /* Return queue slots used count
311  * params:
312  * const q_t *q
313  * returns:
314  * u16
315  */
316 #define CSR_WIFI_HIP_Q_SLOTS_USED(q) \
317  (((q)->q_wr_ptr - (q)->q_rd_ptr < 0)? \
318  ((q)->q_wr_ptr - (q)->q_rd_ptr + (q)->q_length) : ((q)->q_wr_ptr - (q)->q_rd_ptr))
319 
320 /* Return queue slots free count
321  * params:
322  * const q_t *q
323  * returns:
324  * u16
325  */
326 #define CSR_WIFI_HIP_Q_SLOTS_FREE(q) \
327  ((q)->q_length - CSR_WIFI_HIP_Q_SLOTS_USED((q)) - 1)
328 
329 /* Return slot signal data pointer
330  * params:
331  * const q_t *q
332  * u16 slot
333  * returns:
334  * card_signal_t *
335  */
336 #define CSR_WIFI_HIP_Q_SLOT_DATA(q, slot) \
337  ((q)->q_body + slot)
338 
339 /* Return queue next read slot
340  * params:
341  * const q_t *q
342  * returns:
343  * u16 slot offset
344  */
345 #define CSR_WIFI_HIP_Q_NEXT_R_SLOT(q) \
346  ((q)->q_rd_ptr)
347 
348 /* Return queue next write slot
349  * params:
350  * const q_t *q
351  * returns:
352  * u16 slot offset
353  */
354 #define CSR_WIFI_HIP_Q_NEXT_W_SLOT(q) \
355  ((q)->q_wr_ptr)
356 
357 /* Return updated queue pointer wrapped around its length
358  * params:
359  * const q_t *q
360  * u16 x amount to add to queue pointer
361  * returns:
362  * u16 wrapped queue pointer
363  */
364 #define CSR_WIFI_HIP_Q_WRAP(q, x) \
365  ((((x) >= (q)->q_length)?((x) % (q)->q_length) : (x)))
366 
367 /* Advance queue read pointer
368  * params:
369  * const q_t *q
370  */
371 #define CSR_WIFI_HIP_Q_INC_R(q) \
372  ((q)->q_rd_ptr = CSR_WIFI_HIP_Q_WRAP((q), (q)->q_rd_ptr + 1))
373 
374 /* Advance queue write pointer
375  * params:
376  * const q_t *q
377  */
378 #define CSR_WIFI_HIP_Q_INC_W(q) \
379  ((q)->q_wr_ptr = CSR_WIFI_HIP_Q_WRAP((q), (q)->q_wr_ptr + 1))
380 
382 {
386 };
387 
388 typedef struct
389 {
391  unifi_TrafficQueue queue; /* Used for dynamic slot reservation */
392 } slot_desc_t;
393 
394 /*
395  * Structure describing a UniFi SDIO card.
396  */
397 struct card
398 {
399  /*
400  * Back pointer for the higher level OS code. This is passed as
401  * an argument to callbacks (e.g. for received data and indications).
402  */
403  void *ospriv;
404 
405  /*
406  * mapping of HIP slot to MA-PACKET.req host tag, the
407  * array is indexed by slot numbers and each index stores
408  * information of the last host tag it was used for
409  */
410  u32 *fh_slot_host_tag_record;
411 
412 
413  /* Info read from Symbol Table during probe */
414  u32 build_id;
415  char build_id_string[128];
416 
417  /* Retrieve from SDIO driver. */
418  u16 chip_id;
419 
420  /* Read from GBL_CHIP_VERSION. */
422 
423  /* From the SDIO driver (probably 1) */
424  u8 function;
425 
426  /* This is sused to get the register addresses and things. */
427  ChipDescript *helper;
428 
429  /*
430  * Bit mask of PIOs for the loader to waggle during download.
431  * We assume these are connected to LEDs. The main firmware gets
432  * the mask from a MIB entry.
433  */
434  s32 loader_led_mask;
435 
436  /*
437  * Support for flow control. When the from-host queue of signals
438  * is full, we ask the host upper layer to stop sending packets. When
439  * the queue drains we tell it that it can send packets again.
440  * We use this flag to remember the current state.
441  */
442 #define card_is_tx_q_paused(card, q) (card->tx_q_paused_flag[q])
443 #define card_tx_q_unpause(card, q) (card->tx_q_paused_flag[q] = 0)
444 #define card_tx_q_pause(card, q) (card->tx_q_paused_flag[q] = 1)
445 
446  u16 tx_q_paused_flag[UNIFI_TRAFFIC_Q_MAX + 1 + UNIFI_NO_OF_TX_QS]; /* defensive more than big enough */
447 
448  /* UDI callback for logging UniFi interactions */
449  udi_func_t udi_hook;
450 
451  u8 bh_reason_host;
452  u8 bh_reason_unifi;
453 
454  /* SDIO clock speed request from OS layer */
455  u8 request_max_clock;
456 
457  /* Last SDIO clock frequency set */
458  u32 sdio_clock_speed;
459 
460  /*
461  * Current host state (copy of value in IOABORT register and
462  * spinlock to protect it.
463  */
464  enum unifi_host_state host_state;
465 
466  enum unifi_low_power_mode low_power_mode;
467  enum unifi_periodic_wake_mode periodic_wake_mode;
468 
469  /*
470  * Ring buffer of signal structs for a queue of data packets from
471  * the host.
472  * The queue is empty when fh_data_q_num_rd == fh_data_q_num_wr.
473  * To add a packet to the queue, copy it to index given by
474  * (fh_data_q_num_wr%UNIFI_SOFT_Q_LENGTH) and advance fh_data_q_num_wr.
475  * To take a packet from the queue, copy data from index given by
476  * (fh_data_q_num_rd%UNIFI_SOFT_Q_LENGTH) and advance fh_data_q_num_rd.
477  * fh_data_q_num_rd and fh_data_q_num_rd are both modulo 256.
478  */
479  card_signal_t fh_command_q_body[UNIFI_SOFT_COMMAND_Q_LENGTH];
480  q_t fh_command_queue;
481 
483  q_t fh_traffic_queue[UNIFI_NO_OF_TX_QS];
484 
485  /*
486  * Signal counts from UniFi SDIO Control Data Structure.
487  * These are cached and synchronised with the UniFi before and after
488  * a batch of operations.
489  *
490  * These are the modulo-256 count of signals written to or read from UniFi
491  * The value is incremented for every signal.
492  */
493  s32 from_host_signals_w;
494  s32 from_host_signals_r;
495  s32 to_host_signals_r;
496  s32 to_host_signals_w;
497 
498 
499  /* Should specify buffer size as a number of signals */
500  /*
501  * Enough for 10 th and 10 fh data slots:
502  * 1 * 10 * 8 = 80
503  * 2 * 10 * 8 = 160
504  */
505 #define UNIFI_FH_BUF_SIZE 1024
506  struct sigbuf
507  {
508  u8 *buf; /* buffer area */
509  u8 *ptr; /* current pos */
510  u16 count; /* signal count */
512  } fh_buffer;
513  struct sigbuf th_buffer;
514 
515 
516  /*
517  * Field to use for the incrementing value to write to the UniFi
518  * SHARED_IO_INTERRUPT register.
519  * Flag to say we need to generate an interrupt at end of processing.
520  */
521  u32 unifi_interrupt_seq;
522  u8 generate_interrupt;
523 
524 
525  /* Pointers to the bulk data slots */
526  slot_desc_t *from_host_data;
527  bulk_data_desc_t *to_host_data;
528 
529 
530  /*
531  * Index of the next (hopefully) free data slot.
532  * This is an optimisation that starts searching at a more likely point
533  * than the beginning.
534  */
535  s16 from_host_data_head;
536 
537  /* Dynamic slot allocation for queues */
538  card_dynamic_slot_t dynamic_slot_data;
539 
540  /*
541  * SDIO specific fields
542  */
543 
544  /* Interface pointer for the SDIO library */
545  CsrSdioFunction *sdio_if;
546 
547  /* Copy of config_data struct from the card */
548  sdio_config_data_t config_data;
549 
550  /* SDIO address of the Initialised flag and Control Data struct */
551  u32 init_flag_addr;
552  u32 sdio_ctrl_addr;
553 
554  /* The last value written to the Shared Data Memory Page register */
555  u32 proc_select;
556  u32 dmem_page;
557  u32 pmem_page;
558 
559  /* SDIO traffic counters limited to 32 bits for Synergy compatibility */
560  u32 sdio_bytes_read;
561  u32 sdio_bytes_written;
562 
563  u8 memory_resources_allocated;
564 
565  /* UniFi SDIO I/O Block size. */
566  u16 sdio_io_block_size;
567 
568  /* Pad transfer sizes to SDIO block boundaries */
569  u8 sdio_io_block_pad;
570 
571  /* Read from the XBV */
572  struct FWOV fwov;
573 
574 #ifndef CSR_WIFI_HIP_TA_DISABLE
575  /* TA sampling */
576  ta_data_t ta_sampling;
577 #endif
578 
579  /* Auto-coredump */
580  s16 request_coredump_on_reset; /* request coredump on next reset */
581  struct coredump_buf *dump_buf; /* root node */
582  struct coredump_buf *dump_next_write; /* node to fill at next dump */
583  struct coredump_buf *dump_cur_read; /* valid node to read, or NULL */
584 
585 #ifdef CSR_WIFI_HIP_DATA_PLANE_PROFILE
586  struct cmd_profile
587  {
588  u32 cmd52_count;
589  u32 cmd53_count;
590  u32 tx_count;
591  u32 tx_cfm_count;
592  u32 rx_count;
593  u32 bh_count;
594  u32 process_count;
595  u32 protocol_count;
596 
597  u32 cmd52_f0_r_count;
598  u32 cmd52_f0_w_count;
599  u32 cmd52_r8or16_count;
600  u32 cmd52_w8or16_count;
601  u32 cmd52_r16_count;
602  u32 cmd52_w16_count;
603  u32 cmd52_r32_count;
604 
605  u32 sdio_cmd_signal;
606  u32 sdio_cmd_clear_slot;
607  u32 sdio_cmd_to_host;
608  u32 sdio_cmd_from_host;
609  u32 sdio_cmd_from_host_and_clear;
610  } hip_prof;
611  struct cmd_profile cmd_prof;
612 #endif
613 
614  /* Interrupt processing mode flags */
615  u32 intmode;
616 
617 #ifdef UNIFI_DEBUG
618  u8 lsb;
619 #endif
620 
621  /* Historic firmware panic codes */
622  u32 panic_data_phy_addr;
623  u32 panic_data_mac_addr;
624  u16 last_phy_panic_code;
625  u16 last_phy_panic_arg;
626  u16 last_mac_panic_code;
627  u16 last_mac_panic_arg;
628 #ifdef CSR_PRE_ALLOC_NET_DATA
629  bulk_data_desc_t bulk_data_desc_list[BULK_DATA_PRE_ALLOC_NUM];
630  u16 prealloc_netdata_r;
631  u16 prealloc_netdata_w;
632 #endif
633 }; /* struct card */
634 
635 
636 /* Reset types */
638 {
641 };
642 
643 /*
644  * unifi_set_host_state() implements signalling for waking UniFi from
645  * deep sleep. The host indicates to UniFi that it is in one of three states:
646  * Torpid - host has nothing to send, UniFi can go to sleep.
647  * Drowsy - host has data to send to UniFi. UniFi will respond with an
648  * SDIO interrupt. When hosts responds it moves to Awake.
649  * Awake - host has data to transfer, UniFi must stay awake.
650  * When host has finished, it moves to Torpid.
651  */
653 
654 
658 
659 
660 CsrResult unifi_read32(card_t *card, u32 unifi_addr, u32 *pdata);
661 CsrResult unifi_readnz(card_t *card, u32 unifi_addr,
662  void *pdata, u16 len);
664 
665 CsrResult unifi_writen(card_t *card, u32 unifi_addr, void *pdata, u16 len);
666 
668  void *pdata, u32 len, s16 direction);
670  void *pdata, u32 len, s16 direction);
671 #define UNIFI_SDIO_READ 0
672 #define UNIFI_SDIO_WRITE 1
673 
678 
682 
685 
688 
690 #ifdef CSR_PRE_ALLOC_NET_DATA
691 void prealloc_netdata_free(card_t *card);
692 CsrResult prealloc_netdata_alloc(card_t *card);
693 #endif
694 /* For diagnostic use */
695 void dump(void *mem, u16 len);
696 void dump16(void *mem, u16 len);
697 
698 #ifdef __cplusplus
699 }
700 #endif
701 
702 #endif /* __CARD_SDIO_H__ */