aic94xx_hwi.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /*
  2. * Aic94xx SAS/SATA driver hardware interface header file.
  3. *
  4. * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
  5. * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
  6. *
  7. * This file is licensed under GPLv2.
  8. *
  9. * This file is part of the aic94xx driver.
  10. *
  11. * The aic94xx driver is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; version 2 of the
  14. * License.
  15. *
  16. * The aic94xx driver is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with the aic94xx driver; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. */
  26. #ifndef _AIC94XX_HWI_H_
  27. #define _AIC94XX_HWI_H_
  28. #include <linux/interrupt.h>
  29. #include <linux/pci.h>
  30. #include <linux/dma-mapping.h>
  31. #include <scsi/libsas.h>
  32. #include "aic94xx.h"
  33. #include "aic94xx_sas.h"
  34. /* Define ASD_MAX_PHYS to the maximum phys ever. Currently 8. */
  35. #define ASD_MAX_PHYS 8
  36. #define ASD_PCBA_SN_SIZE 12
  37. struct asd_ha_addrspace {
  38. void __iomem *addr;
  39. unsigned long start; /* pci resource start */
  40. unsigned long len; /* pci resource len */
  41. unsigned long flags; /* pci resource flags */
  42. /* addresses internal to the host adapter */
  43. u32 swa_base; /* mmspace 1 (MBAR1) uses this only */
  44. u32 swb_base;
  45. u32 swc_base;
  46. };
  47. struct bios_struct {
  48. int present;
  49. u8 maj;
  50. u8 min;
  51. u32 bld;
  52. };
  53. struct unit_element_struct {
  54. u16 num;
  55. u16 size;
  56. void *area;
  57. };
  58. struct flash_struct {
  59. u32 bar;
  60. int present;
  61. int wide;
  62. u8 manuf;
  63. u8 dev_id;
  64. u8 sec_prot;
  65. u8 method;
  66. u32 dir_offs;
  67. };
  68. struct asd_phy_desc {
  69. /* From CTRL-A settings, then set to what is appropriate */
  70. u8 sas_addr[SAS_ADDR_SIZE];
  71. u8 max_sas_lrate;
  72. u8 min_sas_lrate;
  73. u8 max_sata_lrate;
  74. u8 min_sata_lrate;
  75. u8 flags;
  76. #define ASD_CRC_DIS 1
  77. #define ASD_SATA_SPINUP_HOLD 2
  78. u8 phy_control_0; /* mode 5 reg 0x160 */
  79. u8 phy_control_1; /* mode 5 reg 0x161 */
  80. u8 phy_control_2; /* mode 5 reg 0x162 */
  81. u8 phy_control_3; /* mode 5 reg 0x163 */
  82. };
  83. struct asd_dma_tok {
  84. void *vaddr;
  85. dma_addr_t dma_handle;
  86. size_t size;
  87. };
  88. struct hw_profile {
  89. struct bios_struct bios;
  90. struct unit_element_struct ue;
  91. struct flash_struct flash;
  92. u8 sas_addr[SAS_ADDR_SIZE];
  93. char pcba_sn[ASD_PCBA_SN_SIZE+1];
  94. u8 enabled_phys; /* mask of enabled phys */
  95. struct asd_phy_desc phy_desc[ASD_MAX_PHYS];
  96. u32 max_scbs; /* absolute sequencer scb queue size */
  97. struct asd_dma_tok *scb_ext;
  98. u32 max_ddbs;
  99. struct asd_dma_tok *ddb_ext;
  100. spinlock_t ddb_lock;
  101. void *ddb_bitmap;
  102. int num_phys; /* ENABLEABLE */
  103. int max_phys; /* REPORTED + ENABLEABLE */
  104. unsigned addr_range; /* max # of addrs; max # of possible ports */
  105. unsigned port_name_base;
  106. unsigned dev_name_base;
  107. unsigned sata_name_base;
  108. };
  109. struct asd_ascb {
  110. struct list_head list;
  111. struct asd_ha_struct *ha;
  112. struct scb *scb; /* equals dma_scb->vaddr */
  113. struct asd_dma_tok dma_scb;
  114. struct asd_dma_tok *sg_arr;
  115. void (*tasklet_complete)(struct asd_ascb *, struct done_list_struct *);
  116. u8 uldd_timer:1;
  117. /* internally generated command */
  118. struct timer_list timer;
  119. struct completion *completion;
  120. u8 tag_valid:1;
  121. __be16 tag; /* error recovery only */
  122. /* If this is an Empty SCB, index of first edb in seq->edb_arr. */
  123. int edb_index;
  124. /* Used by the timer timeout function. */
  125. int tc_index;
  126. void *uldd_task;
  127. };
  128. #define ASD_DL_SIZE_BITS 0x8
  129. #define ASD_DL_SIZE (1<<(2+ASD_DL_SIZE_BITS))
  130. #define ASD_DEF_DL_TOGGLE 0x01
  131. struct asd_seq_data {
  132. spinlock_t pend_q_lock;
  133. u16 scbpro;
  134. int pending;
  135. struct list_head pend_q;
  136. int can_queue; /* per adapter */
  137. struct asd_dma_tok next_scb; /* next scb to be delivered to CSEQ */
  138. spinlock_t tc_index_lock;
  139. void **tc_index_array;
  140. void *tc_index_bitmap;
  141. int tc_index_bitmap_bits;
  142. struct tasklet_struct dl_tasklet;
  143. struct done_list_struct *dl; /* array of done list entries, equals */
  144. struct asd_dma_tok *actual_dl; /* actual_dl->vaddr */
  145. int dl_toggle;
  146. int dl_next;
  147. int num_edbs;
  148. struct asd_dma_tok **edb_arr;
  149. int num_escbs;
  150. struct asd_ascb **escb_arr; /* array of pointers to escbs */
  151. };
  152. /* This is an internal port structure. These are used to get accurate
  153. * phy_mask for updating DDB 0.
  154. */
  155. struct asd_port {
  156. u8 sas_addr[SAS_ADDR_SIZE];
  157. u8 attached_sas_addr[SAS_ADDR_SIZE];
  158. u32 phy_mask;
  159. int num_phys;
  160. };
  161. /* This is the Host Adapter structure. It describes the hardware
  162. * SAS adapter.
  163. */
  164. struct asd_ha_struct {
  165. struct pci_dev *pcidev;
  166. const char *name;
  167. struct sas_ha_struct sas_ha;
  168. u8 revision_id;
  169. int iospace;
  170. spinlock_t iolock;
  171. struct asd_ha_addrspace io_handle[2];
  172. struct hw_profile hw_prof;
  173. struct asd_phy phys[ASD_MAX_PHYS];
  174. spinlock_t asd_ports_lock;
  175. struct asd_port asd_ports[ASD_MAX_PHYS];
  176. struct asd_sas_port ports[ASD_MAX_PHYS];
  177. struct dma_pool *scb_pool;
  178. struct asd_seq_data seq; /* sequencer related */
  179. u32 bios_status;
  180. const struct firmware *bios_image;
  181. };
  182. /* ---------- Common macros ---------- */
  183. #define ASD_BUSADDR_LO(__dma_handle) ((u32)(__dma_handle))
  184. #define ASD_BUSADDR_HI(__dma_handle) (((sizeof(dma_addr_t))==8) \
  185. ? ((u32)((__dma_handle) >> 32)) \
  186. : ((u32)0))
  187. #define dev_to_asd_ha(__dev) pci_get_drvdata(to_pci_dev(__dev))
  188. #define SCB_SITE_VALID(__site_no) (((__site_no) & 0xF0FF) != 0x00FF \
  189. && ((__site_no) & 0xF0FF) > 0x001F)
  190. /* For each bit set in __lseq_mask, set __lseq to equal the bit
  191. * position of the set bit and execute the statement following.
  192. * __mc is the temporary mask, used as a mask "counter".
  193. */
  194. #define for_each_sequencer(__lseq_mask, __mc, __lseq) \
  195. for ((__mc)=(__lseq_mask),(__lseq)=0;(__mc)!=0;(__lseq++),(__mc)>>=1)\
  196. if (((__mc) & 1))
  197. #define for_each_phy(__lseq_mask, __mc, __lseq) \
  198. for ((__mc)=(__lseq_mask),(__lseq)=0;(__mc)!=0;(__lseq++),(__mc)>>=1)\
  199. if (((__mc) & 1))
  200. #define PHY_ENABLED(_HA, _I) ((_HA)->hw_prof.enabled_phys & (1<<(_I)))
  201. /* ---------- DMA allocs ---------- */
  202. static inline struct asd_dma_tok *asd_dmatok_alloc(gfp_t flags)
  203. {
  204. return kmem_cache_alloc(asd_dma_token_cache, flags);
  205. }
  206. static inline void asd_dmatok_free(struct asd_dma_tok *token)
  207. {
  208. kmem_cache_free(asd_dma_token_cache, token);
  209. }
  210. static inline struct asd_dma_tok *asd_alloc_coherent(struct asd_ha_struct *
  211. asd_ha, size_t size,
  212. gfp_t flags)
  213. {
  214. struct asd_dma_tok *token = asd_dmatok_alloc(flags);
  215. if (token) {
  216. token->size = size;
  217. token->vaddr = dma_alloc_coherent(&asd_ha->pcidev->dev,
  218. token->size,
  219. &token->dma_handle,
  220. flags);
  221. if (!token->vaddr) {
  222. asd_dmatok_free(token);
  223. token = NULL;
  224. }
  225. }
  226. return token;
  227. }
  228. static inline void asd_free_coherent(struct asd_ha_struct *asd_ha,
  229. struct asd_dma_tok *token)
  230. {
  231. if (token) {
  232. dma_free_coherent(&asd_ha->pcidev->dev, token->size,
  233. token->vaddr, token->dma_handle);
  234. asd_dmatok_free(token);
  235. }
  236. }
  237. static inline void asd_init_ascb(struct asd_ha_struct *asd_ha,
  238. struct asd_ascb *ascb)
  239. {
  240. INIT_LIST_HEAD(&ascb->list);
  241. ascb->scb = ascb->dma_scb.vaddr;
  242. ascb->ha = asd_ha;
  243. ascb->timer.function = NULL;
  244. init_timer(&ascb->timer);
  245. ascb->tc_index = -1;
  246. }
  247. /* Must be called with the tc_index_lock held!
  248. */
  249. static inline void asd_tc_index_release(struct asd_seq_data *seq, int index)
  250. {
  251. seq->tc_index_array[index] = NULL;
  252. clear_bit(index, seq->tc_index_bitmap);
  253. }
  254. /* Must be called with the tc_index_lock held!
  255. */
  256. static inline int asd_tc_index_get(struct asd_seq_data *seq, void *ptr)
  257. {
  258. int index;
  259. index = find_first_zero_bit(seq->tc_index_bitmap,
  260. seq->tc_index_bitmap_bits);
  261. if (index == seq->tc_index_bitmap_bits)
  262. return -1;
  263. seq->tc_index_array[index] = ptr;
  264. set_bit(index, seq->tc_index_bitmap);
  265. return index;
  266. }
  267. /* Must be called with the tc_index_lock held!
  268. */
  269. static inline void *asd_tc_index_find(struct asd_seq_data *seq, int index)
  270. {
  271. return seq->tc_index_array[index];
  272. }
  273. /**
  274. * asd_ascb_free -- free a single aSCB after is has completed
  275. * @ascb: pointer to the aSCB of interest
  276. *
  277. * This frees an aSCB after it has been executed/completed by
  278. * the sequencer.
  279. */
  280. static inline void asd_ascb_free(struct asd_ascb *ascb)
  281. {
  282. if (ascb) {
  283. struct asd_ha_struct *asd_ha = ascb->ha;
  284. unsigned long flags;
  285. BUG_ON(!list_empty(&ascb->list));
  286. spin_lock_irqsave(&ascb->ha->seq.tc_index_lock, flags);
  287. asd_tc_index_release(&ascb->ha->seq, ascb->tc_index);
  288. spin_unlock_irqrestore(&ascb->ha->seq.tc_index_lock, flags);
  289. dma_pool_free(asd_ha->scb_pool, ascb->dma_scb.vaddr,
  290. ascb->dma_scb.dma_handle);
  291. kmem_cache_free(asd_ascb_cache, ascb);
  292. }
  293. }
  294. /**
  295. * asd_ascb_list_free -- free a list of ascbs
  296. * @ascb_list: a list of ascbs
  297. *
  298. * This function will free a list of ascbs allocated by asd_ascb_alloc_list.
  299. * It is used when say the scb queueing function returned QUEUE_FULL,
  300. * and we do not need the ascbs any more.
  301. */
  302. static inline void asd_ascb_free_list(struct asd_ascb *ascb_list)
  303. {
  304. LIST_HEAD(list);
  305. struct list_head *n, *pos;
  306. __list_add(&list, ascb_list->list.prev, &ascb_list->list);
  307. list_for_each_safe(pos, n, &list) {
  308. list_del_init(pos);
  309. asd_ascb_free(list_entry(pos, struct asd_ascb, list));
  310. }
  311. }
  312. /* ---------- Function declarations ---------- */
  313. int asd_init_hw(struct asd_ha_struct *asd_ha);
  314. irqreturn_t asd_hw_isr(int irq, void *dev_id);
  315. struct asd_ascb *asd_ascb_alloc_list(struct asd_ha_struct
  316. *asd_ha, int *num,
  317. gfp_t gfp_mask);
  318. int asd_post_ascb_list(struct asd_ha_struct *asd_ha, struct asd_ascb *ascb,
  319. int num);
  320. int asd_post_escb_list(struct asd_ha_struct *asd_ha, struct asd_ascb *ascb,
  321. int num);
  322. int asd_init_post_escbs(struct asd_ha_struct *asd_ha);
  323. void asd_build_control_phy(struct asd_ascb *ascb, int phy_id, u8 subfunc);
  324. void asd_control_led(struct asd_ha_struct *asd_ha, int phy_id, int op);
  325. void asd_turn_led(struct asd_ha_struct *asd_ha, int phy_id, int op);
  326. int asd_enable_phys(struct asd_ha_struct *asd_ha, const u8 phy_mask);
  327. void asd_ascb_timedout(unsigned long data);
  328. int asd_chip_hardrst(struct asd_ha_struct *asd_ha);
  329. #endif