aic94xx_hwi.h 11 KB

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