bfad.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821
  1. /*
  2. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. /*
  18. * bfad.c Linux driver PCI interface module.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/kthread.h>
  22. #include <linux/errno.h>
  23. #include <linux/sched.h>
  24. #include <linux/init.h>
  25. #include <linux/fs.h>
  26. #include <linux/pci.h>
  27. #include <linux/firmware.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/fcntl.h>
  30. #include "bfad_drv.h"
  31. #include "bfad_im.h"
  32. #include "bfa_fcs.h"
  33. #include "bfa_defs.h"
  34. #include "bfa.h"
  35. BFA_TRC_FILE(LDRV, BFAD);
  36. DEFINE_MUTEX(bfad_mutex);
  37. LIST_HEAD(bfad_list);
  38. static int bfad_inst;
  39. static int num_sgpgs_parm;
  40. int supported_fc4s;
  41. char *host_name, *os_name, *os_patch;
  42. int num_rports, num_ios, num_tms;
  43. int num_fcxps, num_ufbufs;
  44. int reqq_size, rspq_size, num_sgpgs;
  45. int rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT;
  46. int bfa_lun_queue_depth = BFAD_LUN_QUEUE_DEPTH;
  47. int bfa_io_max_sge = BFAD_IO_MAX_SGE;
  48. int bfa_log_level = 3; /* WARNING log level */
  49. int ioc_auto_recover = BFA_TRUE;
  50. int bfa_linkup_delay = -1;
  51. int fdmi_enable = BFA_TRUE;
  52. int pcie_max_read_reqsz;
  53. int bfa_debugfs_enable = 1;
  54. int msix_disable_cb = 0, msix_disable_ct = 0;
  55. int max_xfer_size = BFAD_MAX_SECTORS >> 1;
  56. int max_rport_logins = BFA_FCS_MAX_RPORT_LOGINS;
  57. /* Firmware releated */
  58. u32 bfi_image_cb_size, bfi_image_ct_size, bfi_image_ct2_size;
  59. u32 *bfi_image_cb, *bfi_image_ct, *bfi_image_ct2;
  60. #define BFAD_FW_FILE_CB "/*(DEBLOBBED)*/"
  61. #define BFAD_FW_FILE_CT "/*(DEBLOBBED)*/"
  62. #define BFAD_FW_FILE_CT2 "/*(DEBLOBBED)*/"
  63. static u32 *bfad_load_fwimg(struct pci_dev *pdev);
  64. static void bfad_free_fwimg(void);
  65. static void bfad_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
  66. u32 *bfi_image_size, char *fw_name);
  67. static const char *msix_name_ct[] = {
  68. "ctrl",
  69. "cpe0", "cpe1", "cpe2", "cpe3",
  70. "rme0", "rme1", "rme2", "rme3" };
  71. static const char *msix_name_cb[] = {
  72. "cpe0", "cpe1", "cpe2", "cpe3",
  73. "rme0", "rme1", "rme2", "rme3",
  74. "eemc", "elpu0", "elpu1", "epss", "mlpu" };
  75. /*(DEBLOBBED)*/
  76. module_param(os_name, charp, S_IRUGO | S_IWUSR);
  77. MODULE_PARM_DESC(os_name, "OS name of the hba host machine");
  78. module_param(os_patch, charp, S_IRUGO | S_IWUSR);
  79. MODULE_PARM_DESC(os_patch, "OS patch level of the hba host machine");
  80. module_param(host_name, charp, S_IRUGO | S_IWUSR);
  81. MODULE_PARM_DESC(host_name, "Hostname of the hba host machine");
  82. module_param(num_rports, int, S_IRUGO | S_IWUSR);
  83. MODULE_PARM_DESC(num_rports, "Max number of rports supported per port "
  84. "(physical/logical), default=1024");
  85. module_param(num_ios, int, S_IRUGO | S_IWUSR);
  86. MODULE_PARM_DESC(num_ios, "Max number of ioim requests, default=2000");
  87. module_param(num_tms, int, S_IRUGO | S_IWUSR);
  88. MODULE_PARM_DESC(num_tms, "Max number of task im requests, default=128");
  89. module_param(num_fcxps, int, S_IRUGO | S_IWUSR);
  90. MODULE_PARM_DESC(num_fcxps, "Max number of fcxp requests, default=64");
  91. module_param(num_ufbufs, int, S_IRUGO | S_IWUSR);
  92. MODULE_PARM_DESC(num_ufbufs, "Max number of unsolicited frame "
  93. "buffers, default=64");
  94. module_param(reqq_size, int, S_IRUGO | S_IWUSR);
  95. MODULE_PARM_DESC(reqq_size, "Max number of request queue elements, "
  96. "default=256");
  97. module_param(rspq_size, int, S_IRUGO | S_IWUSR);
  98. MODULE_PARM_DESC(rspq_size, "Max number of response queue elements, "
  99. "default=64");
  100. module_param(num_sgpgs, int, S_IRUGO | S_IWUSR);
  101. MODULE_PARM_DESC(num_sgpgs, "Number of scatter/gather pages, default=2048");
  102. module_param(rport_del_timeout, int, S_IRUGO | S_IWUSR);
  103. MODULE_PARM_DESC(rport_del_timeout, "Rport delete timeout, default=90 secs, "
  104. "Range[>0]");
  105. module_param(bfa_lun_queue_depth, int, S_IRUGO | S_IWUSR);
  106. MODULE_PARM_DESC(bfa_lun_queue_depth, "Lun queue depth, default=32, Range[>0]");
  107. module_param(bfa_io_max_sge, int, S_IRUGO | S_IWUSR);
  108. MODULE_PARM_DESC(bfa_io_max_sge, "Max io scatter/gather elements, default=255");
  109. module_param(bfa_log_level, int, S_IRUGO | S_IWUSR);
  110. MODULE_PARM_DESC(bfa_log_level, "Driver log level, default=3, "
  111. "Range[Critical:1|Error:2|Warning:3|Info:4]");
  112. module_param(ioc_auto_recover, int, S_IRUGO | S_IWUSR);
  113. MODULE_PARM_DESC(ioc_auto_recover, "IOC auto recovery, default=1, "
  114. "Range[off:0|on:1]");
  115. module_param(bfa_linkup_delay, int, S_IRUGO | S_IWUSR);
  116. MODULE_PARM_DESC(bfa_linkup_delay, "Link up delay, default=30 secs for "
  117. "boot port. Otherwise 10 secs in RHEL4 & 0 for "
  118. "[RHEL5, SLES10, ESX40] Range[>0]");
  119. module_param(msix_disable_cb, int, S_IRUGO | S_IWUSR);
  120. MODULE_PARM_DESC(msix_disable_cb, "Disable Message Signaled Interrupts "
  121. "for Brocade-415/425/815/825 cards, default=0, "
  122. " Range[false:0|true:1]");
  123. module_param(msix_disable_ct, int, S_IRUGO | S_IWUSR);
  124. MODULE_PARM_DESC(msix_disable_ct, "Disable Message Signaled Interrupts "
  125. "if possible for Brocade-1010/1020/804/1007/902/1741 "
  126. "cards, default=0, Range[false:0|true:1]");
  127. module_param(fdmi_enable, int, S_IRUGO | S_IWUSR);
  128. MODULE_PARM_DESC(fdmi_enable, "Enables fdmi registration, default=1, "
  129. "Range[false:0|true:1]");
  130. module_param(pcie_max_read_reqsz, int, S_IRUGO | S_IWUSR);
  131. MODULE_PARM_DESC(pcie_max_read_reqsz, "PCIe max read request size, default=0 "
  132. "(use system setting), Range[128|256|512|1024|2048|4096]");
  133. module_param(bfa_debugfs_enable, int, S_IRUGO | S_IWUSR);
  134. MODULE_PARM_DESC(bfa_debugfs_enable, "Enables debugfs feature, default=1,"
  135. " Range[false:0|true:1]");
  136. module_param(max_xfer_size, int, S_IRUGO | S_IWUSR);
  137. MODULE_PARM_DESC(max_xfer_size, "default=32MB,"
  138. " Range[64k|128k|256k|512k|1024k|2048k]");
  139. module_param(max_rport_logins, int, S_IRUGO | S_IWUSR);
  140. MODULE_PARM_DESC(max_rport_logins, "Max number of logins to initiator and target rports on a port (physical/logical), default=1024");
  141. static void
  142. bfad_sm_uninit(struct bfad_s *bfad, enum bfad_sm_event event);
  143. static void
  144. bfad_sm_created(struct bfad_s *bfad, enum bfad_sm_event event);
  145. static void
  146. bfad_sm_initializing(struct bfad_s *bfad, enum bfad_sm_event event);
  147. static void
  148. bfad_sm_operational(struct bfad_s *bfad, enum bfad_sm_event event);
  149. static void
  150. bfad_sm_stopping(struct bfad_s *bfad, enum bfad_sm_event event);
  151. static void
  152. bfad_sm_failed(struct bfad_s *bfad, enum bfad_sm_event event);
  153. static void
  154. bfad_sm_fcs_exit(struct bfad_s *bfad, enum bfad_sm_event event);
  155. /*
  156. * Beginning state for the driver instance, awaiting the pci_probe event
  157. */
  158. static void
  159. bfad_sm_uninit(struct bfad_s *bfad, enum bfad_sm_event event)
  160. {
  161. bfa_trc(bfad, event);
  162. switch (event) {
  163. case BFAD_E_CREATE:
  164. bfa_sm_set_state(bfad, bfad_sm_created);
  165. bfad->bfad_tsk = kthread_create(bfad_worker, (void *) bfad,
  166. "%s", "bfad_worker");
  167. if (IS_ERR(bfad->bfad_tsk)) {
  168. printk(KERN_INFO "bfad[%d]: Kernel thread "
  169. "creation failed!\n", bfad->inst_no);
  170. bfa_sm_send_event(bfad, BFAD_E_KTHREAD_CREATE_FAILED);
  171. }
  172. bfa_sm_send_event(bfad, BFAD_E_INIT);
  173. break;
  174. case BFAD_E_STOP:
  175. /* Ignore stop; already in uninit */
  176. break;
  177. default:
  178. bfa_sm_fault(bfad, event);
  179. }
  180. }
  181. /*
  182. * Driver Instance is created, awaiting event INIT to initialize the bfad
  183. */
  184. static void
  185. bfad_sm_created(struct bfad_s *bfad, enum bfad_sm_event event)
  186. {
  187. unsigned long flags;
  188. bfa_status_t ret;
  189. bfa_trc(bfad, event);
  190. switch (event) {
  191. case BFAD_E_INIT:
  192. bfa_sm_set_state(bfad, bfad_sm_initializing);
  193. init_completion(&bfad->comp);
  194. /* Enable Interrupt and wait bfa_init completion */
  195. if (bfad_setup_intr(bfad)) {
  196. printk(KERN_WARNING "bfad%d: bfad_setup_intr failed\n",
  197. bfad->inst_no);
  198. bfa_sm_send_event(bfad, BFAD_E_INIT_FAILED);
  199. break;
  200. }
  201. spin_lock_irqsave(&bfad->bfad_lock, flags);
  202. bfa_iocfc_init(&bfad->bfa);
  203. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  204. /* Set up interrupt handler for each vectors */
  205. if ((bfad->bfad_flags & BFAD_MSIX_ON) &&
  206. bfad_install_msix_handler(bfad)) {
  207. printk(KERN_WARNING "%s: install_msix failed, bfad%d\n",
  208. __func__, bfad->inst_no);
  209. }
  210. bfad_init_timer(bfad);
  211. wait_for_completion(&bfad->comp);
  212. if ((bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
  213. bfa_sm_send_event(bfad, BFAD_E_INIT_SUCCESS);
  214. } else {
  215. printk(KERN_WARNING
  216. "bfa %s: bfa init failed\n",
  217. bfad->pci_name);
  218. spin_lock_irqsave(&bfad->bfad_lock, flags);
  219. bfa_fcs_init(&bfad->bfa_fcs);
  220. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  221. ret = bfad_cfg_pport(bfad, BFA_LPORT_ROLE_FCP_IM);
  222. if (ret != BFA_STATUS_OK) {
  223. init_completion(&bfad->comp);
  224. spin_lock_irqsave(&bfad->bfad_lock, flags);
  225. bfad->pport.flags |= BFAD_PORT_DELETE;
  226. bfa_fcs_exit(&bfad->bfa_fcs);
  227. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  228. wait_for_completion(&bfad->comp);
  229. bfa_sm_send_event(bfad, BFAD_E_INIT_FAILED);
  230. break;
  231. }
  232. bfad->bfad_flags |= BFAD_HAL_INIT_FAIL;
  233. bfa_sm_send_event(bfad, BFAD_E_HAL_INIT_FAILED);
  234. }
  235. break;
  236. case BFAD_E_KTHREAD_CREATE_FAILED:
  237. bfa_sm_set_state(bfad, bfad_sm_uninit);
  238. break;
  239. default:
  240. bfa_sm_fault(bfad, event);
  241. }
  242. }
  243. static void
  244. bfad_sm_initializing(struct bfad_s *bfad, enum bfad_sm_event event)
  245. {
  246. int retval;
  247. unsigned long flags;
  248. bfa_trc(bfad, event);
  249. switch (event) {
  250. case BFAD_E_INIT_SUCCESS:
  251. kthread_stop(bfad->bfad_tsk);
  252. spin_lock_irqsave(&bfad->bfad_lock, flags);
  253. bfad->bfad_tsk = NULL;
  254. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  255. retval = bfad_start_ops(bfad);
  256. if (retval != BFA_STATUS_OK) {
  257. bfa_sm_set_state(bfad, bfad_sm_failed);
  258. break;
  259. }
  260. bfa_sm_set_state(bfad, bfad_sm_operational);
  261. break;
  262. case BFAD_E_INIT_FAILED:
  263. bfa_sm_set_state(bfad, bfad_sm_uninit);
  264. kthread_stop(bfad->bfad_tsk);
  265. spin_lock_irqsave(&bfad->bfad_lock, flags);
  266. bfad->bfad_tsk = NULL;
  267. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  268. break;
  269. case BFAD_E_HAL_INIT_FAILED:
  270. bfa_sm_set_state(bfad, bfad_sm_failed);
  271. break;
  272. default:
  273. bfa_sm_fault(bfad, event);
  274. }
  275. }
  276. static void
  277. bfad_sm_failed(struct bfad_s *bfad, enum bfad_sm_event event)
  278. {
  279. int retval;
  280. bfa_trc(bfad, event);
  281. switch (event) {
  282. case BFAD_E_INIT_SUCCESS:
  283. retval = bfad_start_ops(bfad);
  284. if (retval != BFA_STATUS_OK)
  285. break;
  286. bfa_sm_set_state(bfad, bfad_sm_operational);
  287. break;
  288. case BFAD_E_STOP:
  289. bfa_sm_set_state(bfad, bfad_sm_fcs_exit);
  290. bfa_sm_send_event(bfad, BFAD_E_FCS_EXIT_COMP);
  291. break;
  292. case BFAD_E_EXIT_COMP:
  293. bfa_sm_set_state(bfad, bfad_sm_uninit);
  294. bfad_remove_intr(bfad);
  295. del_timer_sync(&bfad->hal_tmo);
  296. break;
  297. default:
  298. bfa_sm_fault(bfad, event);
  299. }
  300. }
  301. static void
  302. bfad_sm_operational(struct bfad_s *bfad, enum bfad_sm_event event)
  303. {
  304. bfa_trc(bfad, event);
  305. switch (event) {
  306. case BFAD_E_STOP:
  307. bfa_sm_set_state(bfad, bfad_sm_fcs_exit);
  308. bfad_fcs_stop(bfad);
  309. break;
  310. default:
  311. bfa_sm_fault(bfad, event);
  312. }
  313. }
  314. static void
  315. bfad_sm_fcs_exit(struct bfad_s *bfad, enum bfad_sm_event event)
  316. {
  317. bfa_trc(bfad, event);
  318. switch (event) {
  319. case BFAD_E_FCS_EXIT_COMP:
  320. bfa_sm_set_state(bfad, bfad_sm_stopping);
  321. bfad_stop(bfad);
  322. break;
  323. default:
  324. bfa_sm_fault(bfad, event);
  325. }
  326. }
  327. static void
  328. bfad_sm_stopping(struct bfad_s *bfad, enum bfad_sm_event event)
  329. {
  330. bfa_trc(bfad, event);
  331. switch (event) {
  332. case BFAD_E_EXIT_COMP:
  333. bfa_sm_set_state(bfad, bfad_sm_uninit);
  334. bfad_remove_intr(bfad);
  335. del_timer_sync(&bfad->hal_tmo);
  336. bfad_im_probe_undo(bfad);
  337. bfad->bfad_flags &= ~BFAD_FC4_PROBE_DONE;
  338. bfad_uncfg_pport(bfad);
  339. break;
  340. default:
  341. bfa_sm_fault(bfad, event);
  342. break;
  343. }
  344. }
  345. /*
  346. * BFA callbacks
  347. */
  348. void
  349. bfad_hcb_comp(void *arg, bfa_status_t status)
  350. {
  351. struct bfad_hal_comp *fcomp = (struct bfad_hal_comp *)arg;
  352. fcomp->status = status;
  353. complete(&fcomp->comp);
  354. }
  355. /*
  356. * bfa_init callback
  357. */
  358. void
  359. bfa_cb_init(void *drv, bfa_status_t init_status)
  360. {
  361. struct bfad_s *bfad = drv;
  362. if (init_status == BFA_STATUS_OK) {
  363. bfad->bfad_flags |= BFAD_HAL_INIT_DONE;
  364. /*
  365. * If BFAD_HAL_INIT_FAIL flag is set:
  366. * Wake up the kernel thread to start
  367. * the bfad operations after HAL init done
  368. */
  369. if ((bfad->bfad_flags & BFAD_HAL_INIT_FAIL)) {
  370. bfad->bfad_flags &= ~BFAD_HAL_INIT_FAIL;
  371. wake_up_process(bfad->bfad_tsk);
  372. }
  373. }
  374. complete(&bfad->comp);
  375. }
  376. /*
  377. * BFA_FCS callbacks
  378. */
  379. struct bfad_port_s *
  380. bfa_fcb_lport_new(struct bfad_s *bfad, struct bfa_fcs_lport_s *port,
  381. enum bfa_lport_role roles, struct bfad_vf_s *vf_drv,
  382. struct bfad_vport_s *vp_drv)
  383. {
  384. bfa_status_t rc;
  385. struct bfad_port_s *port_drv;
  386. if (!vp_drv && !vf_drv) {
  387. port_drv = &bfad->pport;
  388. port_drv->pvb_type = BFAD_PORT_PHYS_BASE;
  389. } else if (!vp_drv && vf_drv) {
  390. port_drv = &vf_drv->base_port;
  391. port_drv->pvb_type = BFAD_PORT_VF_BASE;
  392. } else if (vp_drv && !vf_drv) {
  393. port_drv = &vp_drv->drv_port;
  394. port_drv->pvb_type = BFAD_PORT_PHYS_VPORT;
  395. } else {
  396. port_drv = &vp_drv->drv_port;
  397. port_drv->pvb_type = BFAD_PORT_VF_VPORT;
  398. }
  399. port_drv->fcs_port = port;
  400. port_drv->roles = roles;
  401. if (roles & BFA_LPORT_ROLE_FCP_IM) {
  402. rc = bfad_im_port_new(bfad, port_drv);
  403. if (rc != BFA_STATUS_OK) {
  404. bfad_im_port_delete(bfad, port_drv);
  405. port_drv = NULL;
  406. }
  407. }
  408. return port_drv;
  409. }
  410. /*
  411. * FCS RPORT alloc callback, after successful PLOGI by FCS
  412. */
  413. bfa_status_t
  414. bfa_fcb_rport_alloc(struct bfad_s *bfad, struct bfa_fcs_rport_s **rport,
  415. struct bfad_rport_s **rport_drv)
  416. {
  417. bfa_status_t rc = BFA_STATUS_OK;
  418. *rport_drv = kzalloc(sizeof(struct bfad_rport_s), GFP_ATOMIC);
  419. if (*rport_drv == NULL) {
  420. rc = BFA_STATUS_ENOMEM;
  421. goto ext;
  422. }
  423. *rport = &(*rport_drv)->fcs_rport;
  424. ext:
  425. return rc;
  426. }
  427. /*
  428. * FCS PBC VPORT Create
  429. */
  430. void
  431. bfa_fcb_pbc_vport_create(struct bfad_s *bfad, struct bfi_pbc_vport_s pbc_vport)
  432. {
  433. struct bfa_lport_cfg_s port_cfg = {0};
  434. struct bfad_vport_s *vport;
  435. int rc;
  436. vport = kzalloc(sizeof(struct bfad_vport_s), GFP_ATOMIC);
  437. if (!vport) {
  438. bfa_trc(bfad, 0);
  439. return;
  440. }
  441. vport->drv_port.bfad = bfad;
  442. port_cfg.roles = BFA_LPORT_ROLE_FCP_IM;
  443. port_cfg.pwwn = pbc_vport.vp_pwwn;
  444. port_cfg.nwwn = pbc_vport.vp_nwwn;
  445. port_cfg.preboot_vp = BFA_TRUE;
  446. rc = bfa_fcs_pbc_vport_create(&vport->fcs_vport, &bfad->bfa_fcs, 0,
  447. &port_cfg, vport);
  448. if (rc != BFA_STATUS_OK) {
  449. bfa_trc(bfad, 0);
  450. return;
  451. }
  452. list_add_tail(&vport->list_entry, &bfad->pbc_vport_list);
  453. }
  454. void
  455. bfad_hal_mem_release(struct bfad_s *bfad)
  456. {
  457. struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
  458. struct bfa_mem_dma_s *dma_info, *dma_elem;
  459. struct bfa_mem_kva_s *kva_info, *kva_elem;
  460. struct list_head *dm_qe, *km_qe;
  461. dma_info = &hal_meminfo->dma_info;
  462. kva_info = &hal_meminfo->kva_info;
  463. /* Iterate through the KVA meminfo queue */
  464. list_for_each(km_qe, &kva_info->qe) {
  465. kva_elem = (struct bfa_mem_kva_s *) km_qe;
  466. vfree(kva_elem->kva);
  467. }
  468. /* Iterate through the DMA meminfo queue */
  469. list_for_each(dm_qe, &dma_info->qe) {
  470. dma_elem = (struct bfa_mem_dma_s *) dm_qe;
  471. dma_free_coherent(&bfad->pcidev->dev,
  472. dma_elem->mem_len, dma_elem->kva,
  473. (dma_addr_t) dma_elem->dma);
  474. }
  475. memset(hal_meminfo, 0, sizeof(struct bfa_meminfo_s));
  476. }
  477. void
  478. bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg)
  479. {
  480. if (num_rports > 0)
  481. bfa_cfg->fwcfg.num_rports = num_rports;
  482. if (num_ios > 0)
  483. bfa_cfg->fwcfg.num_ioim_reqs = num_ios;
  484. if (num_tms > 0)
  485. bfa_cfg->fwcfg.num_tskim_reqs = num_tms;
  486. if (num_fcxps > 0 && num_fcxps <= BFA_FCXP_MAX)
  487. bfa_cfg->fwcfg.num_fcxp_reqs = num_fcxps;
  488. if (num_ufbufs > 0 && num_ufbufs <= BFA_UF_MAX)
  489. bfa_cfg->fwcfg.num_uf_bufs = num_ufbufs;
  490. if (reqq_size > 0)
  491. bfa_cfg->drvcfg.num_reqq_elems = reqq_size;
  492. if (rspq_size > 0)
  493. bfa_cfg->drvcfg.num_rspq_elems = rspq_size;
  494. if (num_sgpgs > 0 && num_sgpgs <= BFA_SGPG_MAX)
  495. bfa_cfg->drvcfg.num_sgpgs = num_sgpgs;
  496. /*
  497. * populate the hal values back to the driver for sysfs use.
  498. * otherwise, the default values will be shown as 0 in sysfs
  499. */
  500. num_rports = bfa_cfg->fwcfg.num_rports;
  501. num_ios = bfa_cfg->fwcfg.num_ioim_reqs;
  502. num_tms = bfa_cfg->fwcfg.num_tskim_reqs;
  503. num_fcxps = bfa_cfg->fwcfg.num_fcxp_reqs;
  504. num_ufbufs = bfa_cfg->fwcfg.num_uf_bufs;
  505. reqq_size = bfa_cfg->drvcfg.num_reqq_elems;
  506. rspq_size = bfa_cfg->drvcfg.num_rspq_elems;
  507. num_sgpgs = bfa_cfg->drvcfg.num_sgpgs;
  508. }
  509. bfa_status_t
  510. bfad_hal_mem_alloc(struct bfad_s *bfad)
  511. {
  512. struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
  513. struct bfa_mem_dma_s *dma_info, *dma_elem;
  514. struct bfa_mem_kva_s *kva_info, *kva_elem;
  515. struct list_head *dm_qe, *km_qe;
  516. bfa_status_t rc = BFA_STATUS_OK;
  517. dma_addr_t phys_addr;
  518. bfa_cfg_get_default(&bfad->ioc_cfg);
  519. bfad_update_hal_cfg(&bfad->ioc_cfg);
  520. bfad->cfg_data.ioc_queue_depth = bfad->ioc_cfg.fwcfg.num_ioim_reqs;
  521. bfa_cfg_get_meminfo(&bfad->ioc_cfg, hal_meminfo, &bfad->bfa);
  522. dma_info = &hal_meminfo->dma_info;
  523. kva_info = &hal_meminfo->kva_info;
  524. /* Iterate through the KVA meminfo queue */
  525. list_for_each(km_qe, &kva_info->qe) {
  526. kva_elem = (struct bfa_mem_kva_s *) km_qe;
  527. kva_elem->kva = vmalloc(kva_elem->mem_len);
  528. if (kva_elem->kva == NULL) {
  529. bfad_hal_mem_release(bfad);
  530. rc = BFA_STATUS_ENOMEM;
  531. goto ext;
  532. }
  533. memset(kva_elem->kva, 0, kva_elem->mem_len);
  534. }
  535. /* Iterate through the DMA meminfo queue */
  536. list_for_each(dm_qe, &dma_info->qe) {
  537. dma_elem = (struct bfa_mem_dma_s *) dm_qe;
  538. dma_elem->kva = dma_alloc_coherent(&bfad->pcidev->dev,
  539. dma_elem->mem_len,
  540. &phys_addr, GFP_KERNEL);
  541. if (dma_elem->kva == NULL) {
  542. bfad_hal_mem_release(bfad);
  543. rc = BFA_STATUS_ENOMEM;
  544. goto ext;
  545. }
  546. dma_elem->dma = phys_addr;
  547. memset(dma_elem->kva, 0, dma_elem->mem_len);
  548. }
  549. ext:
  550. return rc;
  551. }
  552. /*
  553. * Create a vport under a vf.
  554. */
  555. bfa_status_t
  556. bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
  557. struct bfa_lport_cfg_s *port_cfg, struct device *dev)
  558. {
  559. struct bfad_vport_s *vport;
  560. int rc = BFA_STATUS_OK;
  561. unsigned long flags;
  562. struct completion fcomp;
  563. vport = kzalloc(sizeof(struct bfad_vport_s), GFP_KERNEL);
  564. if (!vport) {
  565. rc = BFA_STATUS_ENOMEM;
  566. goto ext;
  567. }
  568. vport->drv_port.bfad = bfad;
  569. spin_lock_irqsave(&bfad->bfad_lock, flags);
  570. rc = bfa_fcs_vport_create(&vport->fcs_vport, &bfad->bfa_fcs, vf_id,
  571. port_cfg, vport);
  572. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  573. if (rc != BFA_STATUS_OK)
  574. goto ext_free_vport;
  575. if (port_cfg->roles & BFA_LPORT_ROLE_FCP_IM) {
  576. rc = bfad_im_scsi_host_alloc(bfad, vport->drv_port.im_port,
  577. dev);
  578. if (rc != BFA_STATUS_OK)
  579. goto ext_free_fcs_vport;
  580. }
  581. spin_lock_irqsave(&bfad->bfad_lock, flags);
  582. bfa_fcs_vport_start(&vport->fcs_vport);
  583. list_add_tail(&vport->list_entry, &bfad->vport_list);
  584. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  585. return BFA_STATUS_OK;
  586. ext_free_fcs_vport:
  587. spin_lock_irqsave(&bfad->bfad_lock, flags);
  588. vport->comp_del = &fcomp;
  589. init_completion(vport->comp_del);
  590. bfa_fcs_vport_delete(&vport->fcs_vport);
  591. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  592. wait_for_completion(vport->comp_del);
  593. ext_free_vport:
  594. kfree(vport);
  595. ext:
  596. return rc;
  597. }
  598. void
  599. bfad_bfa_tmo(unsigned long data)
  600. {
  601. struct bfad_s *bfad = (struct bfad_s *) data;
  602. unsigned long flags;
  603. struct list_head doneq;
  604. spin_lock_irqsave(&bfad->bfad_lock, flags);
  605. bfa_timer_beat(&bfad->bfa.timer_mod);
  606. bfa_comp_deq(&bfad->bfa, &doneq);
  607. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  608. if (!list_empty(&doneq)) {
  609. bfa_comp_process(&bfad->bfa, &doneq);
  610. spin_lock_irqsave(&bfad->bfad_lock, flags);
  611. bfa_comp_free(&bfad->bfa, &doneq);
  612. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  613. }
  614. mod_timer(&bfad->hal_tmo,
  615. jiffies + msecs_to_jiffies(BFA_TIMER_FREQ));
  616. }
  617. void
  618. bfad_init_timer(struct bfad_s *bfad)
  619. {
  620. init_timer(&bfad->hal_tmo);
  621. bfad->hal_tmo.function = bfad_bfa_tmo;
  622. bfad->hal_tmo.data = (unsigned long)bfad;
  623. mod_timer(&bfad->hal_tmo,
  624. jiffies + msecs_to_jiffies(BFA_TIMER_FREQ));
  625. }
  626. int
  627. bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad)
  628. {
  629. int rc = -ENODEV;
  630. if (pci_enable_device(pdev)) {
  631. printk(KERN_ERR "pci_enable_device fail %p\n", pdev);
  632. goto out;
  633. }
  634. if (pci_request_regions(pdev, BFAD_DRIVER_NAME))
  635. goto out_disable_device;
  636. pci_set_master(pdev);
  637. if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) ||
  638. (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) {
  639. if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) ||
  640. (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)) {
  641. printk(KERN_ERR "pci_set_dma_mask fail %p\n", pdev);
  642. goto out_release_region;
  643. }
  644. }
  645. /* Enable PCIE Advanced Error Recovery (AER) if kernel supports */
  646. pci_enable_pcie_error_reporting(pdev);
  647. bfad->pci_bar0_kva = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
  648. bfad->pci_bar2_kva = pci_iomap(pdev, 2, pci_resource_len(pdev, 2));
  649. if (bfad->pci_bar0_kva == NULL) {
  650. printk(KERN_ERR "Fail to map bar0\n");
  651. goto out_release_region;
  652. }
  653. bfad->hal_pcidev.pci_slot = PCI_SLOT(pdev->devfn);
  654. bfad->hal_pcidev.pci_func = PCI_FUNC(pdev->devfn);
  655. bfad->hal_pcidev.pci_bar_kva = bfad->pci_bar0_kva;
  656. bfad->hal_pcidev.device_id = pdev->device;
  657. bfad->hal_pcidev.ssid = pdev->subsystem_device;
  658. bfad->pci_name = pci_name(pdev);
  659. bfad->pci_attr.vendor_id = pdev->vendor;
  660. bfad->pci_attr.device_id = pdev->device;
  661. bfad->pci_attr.ssid = pdev->subsystem_device;
  662. bfad->pci_attr.ssvid = pdev->subsystem_vendor;
  663. bfad->pci_attr.pcifn = PCI_FUNC(pdev->devfn);
  664. bfad->pcidev = pdev;
  665. /* Adjust PCIe Maximum Read Request Size */
  666. if (pci_is_pcie(pdev) && pcie_max_read_reqsz) {
  667. if (pcie_max_read_reqsz >= 128 &&
  668. pcie_max_read_reqsz <= 4096 &&
  669. is_power_of_2(pcie_max_read_reqsz)) {
  670. int max_rq = pcie_get_readrq(pdev);
  671. printk(KERN_WARNING "BFA[%s]: "
  672. "pcie_max_read_request_size is %d, "
  673. "reset to %d\n", bfad->pci_name, max_rq,
  674. pcie_max_read_reqsz);
  675. pcie_set_readrq(pdev, pcie_max_read_reqsz);
  676. } else {
  677. printk(KERN_WARNING "BFA[%s]: invalid "
  678. "pcie_max_read_request_size %d ignored\n",
  679. bfad->pci_name, pcie_max_read_reqsz);
  680. }
  681. }
  682. pci_save_state(pdev);
  683. return 0;
  684. out_release_region:
  685. pci_release_regions(pdev);
  686. out_disable_device:
  687. pci_disable_device(pdev);
  688. out:
  689. return rc;
  690. }
  691. void
  692. bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad)
  693. {
  694. pci_iounmap(pdev, bfad->pci_bar0_kva);
  695. pci_iounmap(pdev, bfad->pci_bar2_kva);
  696. pci_release_regions(pdev);
  697. /* Disable PCIE Advanced Error Recovery (AER) */
  698. pci_disable_pcie_error_reporting(pdev);
  699. pci_disable_device(pdev);
  700. }
  701. bfa_status_t
  702. bfad_drv_init(struct bfad_s *bfad)
  703. {
  704. bfa_status_t rc;
  705. unsigned long flags;
  706. bfad->cfg_data.rport_del_timeout = rport_del_timeout;
  707. bfad->cfg_data.lun_queue_depth = bfa_lun_queue_depth;
  708. bfad->cfg_data.io_max_sge = bfa_io_max_sge;
  709. bfad->cfg_data.binding_method = FCP_PWWN_BINDING;
  710. rc = bfad_hal_mem_alloc(bfad);
  711. if (rc != BFA_STATUS_OK) {
  712. printk(KERN_WARNING "bfad%d bfad_hal_mem_alloc failure\n",
  713. bfad->inst_no);
  714. printk(KERN_WARNING
  715. "Not enough memory to attach all Brocade HBA ports, %s",
  716. "System may need more memory.\n");
  717. return BFA_STATUS_FAILED;
  718. }
  719. bfad->bfa.trcmod = bfad->trcmod;
  720. bfad->bfa.plog = &bfad->plog_buf;
  721. bfa_plog_init(&bfad->plog_buf);
  722. bfa_plog_str(&bfad->plog_buf, BFA_PL_MID_DRVR, BFA_PL_EID_DRIVER_START,
  723. 0, "Driver Attach");
  724. bfa_attach(&bfad->bfa, bfad, &bfad->ioc_cfg, &bfad->meminfo,
  725. &bfad->hal_pcidev);
  726. /* FCS INIT */
  727. spin_lock_irqsave(&bfad->bfad_lock, flags);
  728. bfad->bfa_fcs.trcmod = bfad->trcmod;
  729. bfa_fcs_attach(&bfad->bfa_fcs, &bfad->bfa, bfad, BFA_FALSE);
  730. bfad->bfa_fcs.fdmi_enabled = fdmi_enable;
  731. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  732. bfad->bfad_flags |= BFAD_DRV_INIT_DONE;
  733. return BFA_STATUS_OK;
  734. }
  735. void
  736. bfad_drv_uninit(struct bfad_s *bfad)
  737. {
  738. unsigned long flags;
  739. spin_lock_irqsave(&bfad->bfad_lock, flags);
  740. init_completion(&bfad->comp);
  741. bfa_iocfc_stop(&bfad->bfa);
  742. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  743. wait_for_completion(&bfad->comp);
  744. del_timer_sync(&bfad->hal_tmo);
  745. bfa_isr_disable(&bfad->bfa);
  746. bfa_detach(&bfad->bfa);
  747. bfad_remove_intr(bfad);
  748. bfad_hal_mem_release(bfad);
  749. bfad->bfad_flags &= ~BFAD_DRV_INIT_DONE;
  750. }
  751. void
  752. bfad_drv_start(struct bfad_s *bfad)
  753. {
  754. unsigned long flags;
  755. spin_lock_irqsave(&bfad->bfad_lock, flags);
  756. bfa_iocfc_start(&bfad->bfa);
  757. bfa_fcs_pbc_vport_init(&bfad->bfa_fcs);
  758. bfa_fcs_fabric_modstart(&bfad->bfa_fcs);
  759. bfad->bfad_flags |= BFAD_HAL_START_DONE;
  760. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  761. if (bfad->im)
  762. flush_workqueue(bfad->im->drv_workq);
  763. }
  764. void
  765. bfad_fcs_stop(struct bfad_s *bfad)
  766. {
  767. unsigned long flags;
  768. spin_lock_irqsave(&bfad->bfad_lock, flags);
  769. init_completion(&bfad->comp);
  770. bfad->pport.flags |= BFAD_PORT_DELETE;
  771. bfa_fcs_exit(&bfad->bfa_fcs);
  772. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  773. wait_for_completion(&bfad->comp);
  774. bfa_sm_send_event(bfad, BFAD_E_FCS_EXIT_COMP);
  775. }
  776. void
  777. bfad_stop(struct bfad_s *bfad)
  778. {
  779. unsigned long flags;
  780. spin_lock_irqsave(&bfad->bfad_lock, flags);
  781. init_completion(&bfad->comp);
  782. bfa_iocfc_stop(&bfad->bfa);
  783. bfad->bfad_flags &= ~BFAD_HAL_START_DONE;
  784. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  785. wait_for_completion(&bfad->comp);
  786. bfa_sm_send_event(bfad, BFAD_E_EXIT_COMP);
  787. }
  788. bfa_status_t
  789. bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role)
  790. {
  791. int rc = BFA_STATUS_OK;
  792. /* Allocate scsi_host for the physical port */
  793. if ((supported_fc4s & BFA_LPORT_ROLE_FCP_IM) &&
  794. (role & BFA_LPORT_ROLE_FCP_IM)) {
  795. if (bfad->pport.im_port == NULL) {
  796. rc = BFA_STATUS_FAILED;
  797. goto out;
  798. }
  799. rc = bfad_im_scsi_host_alloc(bfad, bfad->pport.im_port,
  800. &bfad->pcidev->dev);
  801. if (rc != BFA_STATUS_OK)
  802. goto out;
  803. bfad->pport.roles |= BFA_LPORT_ROLE_FCP_IM;
  804. }
  805. bfad->bfad_flags |= BFAD_CFG_PPORT_DONE;
  806. out:
  807. return rc;
  808. }
  809. void
  810. bfad_uncfg_pport(struct bfad_s *bfad)
  811. {
  812. if ((supported_fc4s & BFA_LPORT_ROLE_FCP_IM) &&
  813. (bfad->pport.roles & BFA_LPORT_ROLE_FCP_IM)) {
  814. bfad_im_scsi_host_free(bfad, bfad->pport.im_port);
  815. bfad_im_port_clean(bfad->pport.im_port);
  816. kfree(bfad->pport.im_port);
  817. bfad->pport.roles &= ~BFA_LPORT_ROLE_FCP_IM;
  818. }
  819. bfad->bfad_flags &= ~BFAD_CFG_PPORT_DONE;
  820. }
  821. bfa_status_t
  822. bfad_start_ops(struct bfad_s *bfad) {
  823. int retval;
  824. unsigned long flags;
  825. struct bfad_vport_s *vport, *vport_new;
  826. struct bfa_fcs_driver_info_s driver_info;
  827. /* Limit min/max. xfer size to [64k-32MB] */
  828. if (max_xfer_size < BFAD_MIN_SECTORS >> 1)
  829. max_xfer_size = BFAD_MIN_SECTORS >> 1;
  830. if (max_xfer_size > BFAD_MAX_SECTORS >> 1)
  831. max_xfer_size = BFAD_MAX_SECTORS >> 1;
  832. /* Fill the driver_info info to fcs*/
  833. memset(&driver_info, 0, sizeof(driver_info));
  834. strncpy(driver_info.version, BFAD_DRIVER_VERSION,
  835. sizeof(driver_info.version) - 1);
  836. if (host_name)
  837. strncpy(driver_info.host_machine_name, host_name,
  838. sizeof(driver_info.host_machine_name) - 1);
  839. if (os_name)
  840. strncpy(driver_info.host_os_name, os_name,
  841. sizeof(driver_info.host_os_name) - 1);
  842. if (os_patch)
  843. strncpy(driver_info.host_os_patch, os_patch,
  844. sizeof(driver_info.host_os_patch) - 1);
  845. strncpy(driver_info.os_device_name, bfad->pci_name,
  846. sizeof(driver_info.os_device_name) - 1);
  847. /* FCS driver info init */
  848. spin_lock_irqsave(&bfad->bfad_lock, flags);
  849. bfa_fcs_driver_info_init(&bfad->bfa_fcs, &driver_info);
  850. if (bfad->bfad_flags & BFAD_CFG_PPORT_DONE)
  851. bfa_fcs_update_cfg(&bfad->bfa_fcs);
  852. else
  853. bfa_fcs_init(&bfad->bfa_fcs);
  854. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  855. if (!(bfad->bfad_flags & BFAD_CFG_PPORT_DONE)) {
  856. retval = bfad_cfg_pport(bfad, BFA_LPORT_ROLE_FCP_IM);
  857. if (retval != BFA_STATUS_OK)
  858. return BFA_STATUS_FAILED;
  859. }
  860. /* Setup fc host fixed attribute if the lk supports */
  861. bfad_fc_host_init(bfad->pport.im_port);
  862. /* BFAD level FC4 IM specific resource allocation */
  863. retval = bfad_im_probe(bfad);
  864. if (retval != BFA_STATUS_OK) {
  865. printk(KERN_WARNING "bfad_im_probe failed\n");
  866. if (bfa_sm_cmp_state(bfad, bfad_sm_initializing))
  867. bfa_sm_set_state(bfad, bfad_sm_failed);
  868. return BFA_STATUS_FAILED;
  869. } else
  870. bfad->bfad_flags |= BFAD_FC4_PROBE_DONE;
  871. bfad_drv_start(bfad);
  872. /* Complete pbc vport create */
  873. list_for_each_entry_safe(vport, vport_new, &bfad->pbc_vport_list,
  874. list_entry) {
  875. struct fc_vport_identifiers vid;
  876. struct fc_vport *fc_vport;
  877. char pwwn_buf[BFA_STRING_32];
  878. memset(&vid, 0, sizeof(vid));
  879. vid.roles = FC_PORT_ROLE_FCP_INITIATOR;
  880. vid.vport_type = FC_PORTTYPE_NPIV;
  881. vid.disable = false;
  882. vid.node_name = wwn_to_u64((u8 *)
  883. (&((vport->fcs_vport).lport.port_cfg.nwwn)));
  884. vid.port_name = wwn_to_u64((u8 *)
  885. (&((vport->fcs_vport).lport.port_cfg.pwwn)));
  886. fc_vport = fc_vport_create(bfad->pport.im_port->shost, 0, &vid);
  887. if (!fc_vport) {
  888. wwn2str(pwwn_buf, vid.port_name);
  889. printk(KERN_WARNING "bfad%d: failed to create pbc vport"
  890. " %s\n", bfad->inst_no, pwwn_buf);
  891. }
  892. list_del(&vport->list_entry);
  893. kfree(vport);
  894. }
  895. /*
  896. * If bfa_linkup_delay is set to -1 default; try to retrive the
  897. * value using the bfad_get_linkup_delay(); else use the
  898. * passed in module param value as the bfa_linkup_delay.
  899. */
  900. if (bfa_linkup_delay < 0) {
  901. bfa_linkup_delay = bfad_get_linkup_delay(bfad);
  902. bfad_rport_online_wait(bfad);
  903. bfa_linkup_delay = -1;
  904. } else
  905. bfad_rport_online_wait(bfad);
  906. BFA_LOG(KERN_INFO, bfad, bfa_log_level, "bfa device claimed\n");
  907. return BFA_STATUS_OK;
  908. }
  909. int
  910. bfad_worker(void *ptr)
  911. {
  912. struct bfad_s *bfad = ptr;
  913. unsigned long flags;
  914. if (kthread_should_stop())
  915. return 0;
  916. /* Send event BFAD_E_INIT_SUCCESS */
  917. bfa_sm_send_event(bfad, BFAD_E_INIT_SUCCESS);
  918. spin_lock_irqsave(&bfad->bfad_lock, flags);
  919. bfad->bfad_tsk = NULL;
  920. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  921. return 0;
  922. }
  923. /*
  924. * BFA driver interrupt functions
  925. */
  926. irqreturn_t
  927. bfad_intx(int irq, void *dev_id)
  928. {
  929. struct bfad_s *bfad = dev_id;
  930. struct list_head doneq;
  931. unsigned long flags;
  932. bfa_boolean_t rc;
  933. spin_lock_irqsave(&bfad->bfad_lock, flags);
  934. rc = bfa_intx(&bfad->bfa);
  935. if (!rc) {
  936. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  937. return IRQ_NONE;
  938. }
  939. bfa_comp_deq(&bfad->bfa, &doneq);
  940. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  941. if (!list_empty(&doneq)) {
  942. bfa_comp_process(&bfad->bfa, &doneq);
  943. spin_lock_irqsave(&bfad->bfad_lock, flags);
  944. bfa_comp_free(&bfad->bfa, &doneq);
  945. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  946. }
  947. return IRQ_HANDLED;
  948. }
  949. static irqreturn_t
  950. bfad_msix(int irq, void *dev_id)
  951. {
  952. struct bfad_msix_s *vec = dev_id;
  953. struct bfad_s *bfad = vec->bfad;
  954. struct list_head doneq;
  955. unsigned long flags;
  956. spin_lock_irqsave(&bfad->bfad_lock, flags);
  957. bfa_msix(&bfad->bfa, vec->msix.entry);
  958. bfa_comp_deq(&bfad->bfa, &doneq);
  959. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  960. if (!list_empty(&doneq)) {
  961. bfa_comp_process(&bfad->bfa, &doneq);
  962. spin_lock_irqsave(&bfad->bfad_lock, flags);
  963. bfa_comp_free(&bfad->bfa, &doneq);
  964. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  965. }
  966. return IRQ_HANDLED;
  967. }
  968. /*
  969. * Initialize the MSIX entry table.
  970. */
  971. static void
  972. bfad_init_msix_entry(struct bfad_s *bfad, struct msix_entry *msix_entries,
  973. int mask, int max_bit)
  974. {
  975. int i;
  976. int match = 0x00000001;
  977. for (i = 0, bfad->nvec = 0; i < MAX_MSIX_ENTRY; i++) {
  978. if (mask & match) {
  979. bfad->msix_tab[bfad->nvec].msix.entry = i;
  980. bfad->msix_tab[bfad->nvec].bfad = bfad;
  981. msix_entries[bfad->nvec].entry = i;
  982. bfad->nvec++;
  983. }
  984. match <<= 1;
  985. }
  986. }
  987. int
  988. bfad_install_msix_handler(struct bfad_s *bfad)
  989. {
  990. int i, error = 0;
  991. for (i = 0; i < bfad->nvec; i++) {
  992. sprintf(bfad->msix_tab[i].name, "bfa-%s-%s",
  993. bfad->pci_name,
  994. ((bfa_asic_id_cb(bfad->hal_pcidev.device_id)) ?
  995. msix_name_cb[i] : msix_name_ct[i]));
  996. error = request_irq(bfad->msix_tab[i].msix.vector,
  997. (irq_handler_t) bfad_msix, 0,
  998. bfad->msix_tab[i].name, &bfad->msix_tab[i]);
  999. bfa_trc(bfad, i);
  1000. bfa_trc(bfad, bfad->msix_tab[i].msix.vector);
  1001. if (error) {
  1002. int j;
  1003. for (j = 0; j < i; j++)
  1004. free_irq(bfad->msix_tab[j].msix.vector,
  1005. &bfad->msix_tab[j]);
  1006. bfad->bfad_flags &= ~BFAD_MSIX_ON;
  1007. pci_disable_msix(bfad->pcidev);
  1008. return 1;
  1009. }
  1010. }
  1011. return 0;
  1012. }
  1013. /*
  1014. * Setup MSIX based interrupt.
  1015. */
  1016. int
  1017. bfad_setup_intr(struct bfad_s *bfad)
  1018. {
  1019. int error;
  1020. u32 mask = 0, i, num_bit = 0, max_bit = 0;
  1021. struct msix_entry msix_entries[MAX_MSIX_ENTRY];
  1022. struct pci_dev *pdev = bfad->pcidev;
  1023. u16 reg;
  1024. /* Call BFA to get the msix map for this PCI function. */
  1025. bfa_msix_getvecs(&bfad->bfa, &mask, &num_bit, &max_bit);
  1026. /* Set up the msix entry table */
  1027. bfad_init_msix_entry(bfad, msix_entries, mask, max_bit);
  1028. if ((bfa_asic_id_ctc(pdev->device) && !msix_disable_ct) ||
  1029. (bfa_asic_id_cb(pdev->device) && !msix_disable_cb)) {
  1030. error = pci_enable_msix_exact(bfad->pcidev,
  1031. msix_entries, bfad->nvec);
  1032. /* In CT1 & CT2, try to allocate just one vector */
  1033. if (error == -ENOSPC && bfa_asic_id_ctc(pdev->device)) {
  1034. printk(KERN_WARNING "bfa %s: trying one msix "
  1035. "vector failed to allocate %d[%d]\n",
  1036. bfad->pci_name, bfad->nvec, error);
  1037. bfad->nvec = 1;
  1038. error = pci_enable_msix_exact(bfad->pcidev,
  1039. msix_entries, 1);
  1040. }
  1041. if (error) {
  1042. printk(KERN_WARNING "bfad%d: "
  1043. "pci_enable_msix_exact failed (%d), "
  1044. "use line based.\n",
  1045. bfad->inst_no, error);
  1046. goto line_based;
  1047. }
  1048. /* Disable INTX in MSI-X mode */
  1049. pci_read_config_word(pdev, PCI_COMMAND, &reg);
  1050. if (!(reg & PCI_COMMAND_INTX_DISABLE))
  1051. pci_write_config_word(pdev, PCI_COMMAND,
  1052. reg | PCI_COMMAND_INTX_DISABLE);
  1053. /* Save the vectors */
  1054. for (i = 0; i < bfad->nvec; i++) {
  1055. bfa_trc(bfad, msix_entries[i].vector);
  1056. bfad->msix_tab[i].msix.vector = msix_entries[i].vector;
  1057. }
  1058. bfa_msix_init(&bfad->bfa, bfad->nvec);
  1059. bfad->bfad_flags |= BFAD_MSIX_ON;
  1060. return 0;
  1061. }
  1062. line_based:
  1063. error = request_irq(bfad->pcidev->irq, (irq_handler_t)bfad_intx,
  1064. BFAD_IRQ_FLAGS, BFAD_DRIVER_NAME, bfad);
  1065. if (error)
  1066. return error;
  1067. bfad->bfad_flags |= BFAD_INTX_ON;
  1068. return 0;
  1069. }
  1070. void
  1071. bfad_remove_intr(struct bfad_s *bfad)
  1072. {
  1073. int i;
  1074. if (bfad->bfad_flags & BFAD_MSIX_ON) {
  1075. for (i = 0; i < bfad->nvec; i++)
  1076. free_irq(bfad->msix_tab[i].msix.vector,
  1077. &bfad->msix_tab[i]);
  1078. pci_disable_msix(bfad->pcidev);
  1079. bfad->bfad_flags &= ~BFAD_MSIX_ON;
  1080. } else if (bfad->bfad_flags & BFAD_INTX_ON) {
  1081. free_irq(bfad->pcidev->irq, bfad);
  1082. }
  1083. }
  1084. /*
  1085. * PCI probe entry.
  1086. */
  1087. int
  1088. bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
  1089. {
  1090. struct bfad_s *bfad;
  1091. int error = -ENODEV, retval, i;
  1092. /* For single port cards - only claim function 0 */
  1093. if ((pdev->device == BFA_PCI_DEVICE_ID_FC_8G1P) &&
  1094. (PCI_FUNC(pdev->devfn) != 0))
  1095. return -ENODEV;
  1096. bfad = kzalloc(sizeof(struct bfad_s), GFP_KERNEL);
  1097. if (!bfad) {
  1098. error = -ENOMEM;
  1099. goto out;
  1100. }
  1101. bfad->trcmod = kzalloc(sizeof(struct bfa_trc_mod_s), GFP_KERNEL);
  1102. if (!bfad->trcmod) {
  1103. printk(KERN_WARNING "Error alloc trace buffer!\n");
  1104. error = -ENOMEM;
  1105. goto out_alloc_trace_failure;
  1106. }
  1107. /* TRACE INIT */
  1108. bfa_trc_init(bfad->trcmod);
  1109. bfa_trc(bfad, bfad_inst);
  1110. /* AEN INIT */
  1111. INIT_LIST_HEAD(&bfad->free_aen_q);
  1112. INIT_LIST_HEAD(&bfad->active_aen_q);
  1113. for (i = 0; i < BFA_AEN_MAX_ENTRY; i++)
  1114. list_add_tail(&bfad->aen_list[i].qe, &bfad->free_aen_q);
  1115. if (!(bfad_load_fwimg(pdev))) {
  1116. kfree(bfad->trcmod);
  1117. goto out_alloc_trace_failure;
  1118. }
  1119. retval = bfad_pci_init(pdev, bfad);
  1120. if (retval) {
  1121. printk(KERN_WARNING "bfad_pci_init failure!\n");
  1122. error = retval;
  1123. goto out_pci_init_failure;
  1124. }
  1125. mutex_lock(&bfad_mutex);
  1126. bfad->inst_no = bfad_inst++;
  1127. list_add_tail(&bfad->list_entry, &bfad_list);
  1128. mutex_unlock(&bfad_mutex);
  1129. /* Initializing the state machine: State set to uninit */
  1130. bfa_sm_set_state(bfad, bfad_sm_uninit);
  1131. spin_lock_init(&bfad->bfad_lock);
  1132. spin_lock_init(&bfad->bfad_aen_spinlock);
  1133. pci_set_drvdata(pdev, bfad);
  1134. bfad->ref_count = 0;
  1135. bfad->pport.bfad = bfad;
  1136. INIT_LIST_HEAD(&bfad->pbc_vport_list);
  1137. INIT_LIST_HEAD(&bfad->vport_list);
  1138. /* Setup the debugfs node for this bfad */
  1139. if (bfa_debugfs_enable)
  1140. bfad_debugfs_init(&bfad->pport);
  1141. retval = bfad_drv_init(bfad);
  1142. if (retval != BFA_STATUS_OK)
  1143. goto out_drv_init_failure;
  1144. bfa_sm_send_event(bfad, BFAD_E_CREATE);
  1145. if (bfa_sm_cmp_state(bfad, bfad_sm_uninit))
  1146. goto out_bfad_sm_failure;
  1147. return 0;
  1148. out_bfad_sm_failure:
  1149. bfad_hal_mem_release(bfad);
  1150. out_drv_init_failure:
  1151. /* Remove the debugfs node for this bfad */
  1152. kfree(bfad->regdata);
  1153. bfad_debugfs_exit(&bfad->pport);
  1154. mutex_lock(&bfad_mutex);
  1155. bfad_inst--;
  1156. list_del(&bfad->list_entry);
  1157. mutex_unlock(&bfad_mutex);
  1158. bfad_pci_uninit(pdev, bfad);
  1159. out_pci_init_failure:
  1160. kfree(bfad->trcmod);
  1161. out_alloc_trace_failure:
  1162. kfree(bfad);
  1163. out:
  1164. return error;
  1165. }
  1166. /*
  1167. * PCI remove entry.
  1168. */
  1169. void
  1170. bfad_pci_remove(struct pci_dev *pdev)
  1171. {
  1172. struct bfad_s *bfad = pci_get_drvdata(pdev);
  1173. unsigned long flags;
  1174. bfa_trc(bfad, bfad->inst_no);
  1175. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1176. if (bfad->bfad_tsk != NULL) {
  1177. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1178. kthread_stop(bfad->bfad_tsk);
  1179. } else {
  1180. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1181. }
  1182. /* Send Event BFAD_E_STOP */
  1183. bfa_sm_send_event(bfad, BFAD_E_STOP);
  1184. /* Driver detach and dealloc mem */
  1185. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1186. bfa_detach(&bfad->bfa);
  1187. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1188. bfad_hal_mem_release(bfad);
  1189. /* Remove the debugfs node for this bfad */
  1190. kfree(bfad->regdata);
  1191. bfad_debugfs_exit(&bfad->pport);
  1192. /* Cleaning the BFAD instance */
  1193. mutex_lock(&bfad_mutex);
  1194. bfad_inst--;
  1195. list_del(&bfad->list_entry);
  1196. mutex_unlock(&bfad_mutex);
  1197. bfad_pci_uninit(pdev, bfad);
  1198. kfree(bfad->trcmod);
  1199. kfree(bfad);
  1200. }
  1201. /*
  1202. * PCI Error Recovery entry, error detected.
  1203. */
  1204. static pci_ers_result_t
  1205. bfad_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  1206. {
  1207. struct bfad_s *bfad = pci_get_drvdata(pdev);
  1208. unsigned long flags;
  1209. pci_ers_result_t ret = PCI_ERS_RESULT_NONE;
  1210. dev_printk(KERN_ERR, &pdev->dev,
  1211. "error detected state: %d - flags: 0x%x\n",
  1212. state, bfad->bfad_flags);
  1213. switch (state) {
  1214. case pci_channel_io_normal: /* non-fatal error */
  1215. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1216. bfad->bfad_flags &= ~BFAD_EEH_BUSY;
  1217. /* Suspend/fail all bfa operations */
  1218. bfa_ioc_suspend(&bfad->bfa.ioc);
  1219. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1220. del_timer_sync(&bfad->hal_tmo);
  1221. ret = PCI_ERS_RESULT_CAN_RECOVER;
  1222. break;
  1223. case pci_channel_io_frozen: /* fatal error */
  1224. init_completion(&bfad->comp);
  1225. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1226. bfad->bfad_flags |= BFAD_EEH_BUSY;
  1227. /* Suspend/fail all bfa operations */
  1228. bfa_ioc_suspend(&bfad->bfa.ioc);
  1229. bfa_fcs_stop(&bfad->bfa_fcs);
  1230. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1231. wait_for_completion(&bfad->comp);
  1232. bfad_remove_intr(bfad);
  1233. del_timer_sync(&bfad->hal_tmo);
  1234. pci_disable_device(pdev);
  1235. ret = PCI_ERS_RESULT_NEED_RESET;
  1236. break;
  1237. case pci_channel_io_perm_failure: /* PCI Card is DEAD */
  1238. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1239. bfad->bfad_flags |= BFAD_EEH_BUSY |
  1240. BFAD_EEH_PCI_CHANNEL_IO_PERM_FAILURE;
  1241. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1242. /* If the error_detected handler is called with the reason
  1243. * pci_channel_io_perm_failure - it will subsequently call
  1244. * pci_remove() entry point to remove the pci device from the
  1245. * system - So defer the cleanup to pci_remove(); cleaning up
  1246. * here causes inconsistent state during pci_remove().
  1247. */
  1248. ret = PCI_ERS_RESULT_DISCONNECT;
  1249. break;
  1250. default:
  1251. WARN_ON(1);
  1252. }
  1253. return ret;
  1254. }
  1255. int
  1256. restart_bfa(struct bfad_s *bfad)
  1257. {
  1258. unsigned long flags;
  1259. struct pci_dev *pdev = bfad->pcidev;
  1260. bfa_attach(&bfad->bfa, bfad, &bfad->ioc_cfg,
  1261. &bfad->meminfo, &bfad->hal_pcidev);
  1262. /* Enable Interrupt and wait bfa_init completion */
  1263. if (bfad_setup_intr(bfad)) {
  1264. dev_printk(KERN_WARNING, &pdev->dev,
  1265. "%s: bfad_setup_intr failed\n", bfad->pci_name);
  1266. bfa_sm_send_event(bfad, BFAD_E_INIT_FAILED);
  1267. return -1;
  1268. }
  1269. init_completion(&bfad->comp);
  1270. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1271. bfa_iocfc_init(&bfad->bfa);
  1272. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1273. /* Set up interrupt handler for each vectors */
  1274. if ((bfad->bfad_flags & BFAD_MSIX_ON) &&
  1275. bfad_install_msix_handler(bfad))
  1276. dev_printk(KERN_WARNING, &pdev->dev,
  1277. "%s: install_msix failed.\n", bfad->pci_name);
  1278. bfad_init_timer(bfad);
  1279. wait_for_completion(&bfad->comp);
  1280. bfad_drv_start(bfad);
  1281. return 0;
  1282. }
  1283. /*
  1284. * PCI Error Recovery entry, re-initialize the chip.
  1285. */
  1286. static pci_ers_result_t
  1287. bfad_pci_slot_reset(struct pci_dev *pdev)
  1288. {
  1289. struct bfad_s *bfad = pci_get_drvdata(pdev);
  1290. u8 byte;
  1291. dev_printk(KERN_ERR, &pdev->dev,
  1292. "bfad_pci_slot_reset flags: 0x%x\n", bfad->bfad_flags);
  1293. if (pci_enable_device(pdev)) {
  1294. dev_printk(KERN_ERR, &pdev->dev, "Cannot re-enable "
  1295. "PCI device after reset.\n");
  1296. return PCI_ERS_RESULT_DISCONNECT;
  1297. }
  1298. pci_restore_state(pdev);
  1299. /*
  1300. * Read some byte (e.g. DMA max. payload size which can't
  1301. * be 0xff any time) to make sure - we did not hit another PCI error
  1302. * in the middle of recovery. If we did, then declare permanent failure.
  1303. */
  1304. pci_read_config_byte(pdev, 0x68, &byte);
  1305. if (byte == 0xff) {
  1306. dev_printk(KERN_ERR, &pdev->dev,
  1307. "slot_reset failed ... got another PCI error !\n");
  1308. goto out_disable_device;
  1309. }
  1310. pci_save_state(pdev);
  1311. pci_set_master(pdev);
  1312. if (pci_set_dma_mask(bfad->pcidev, DMA_BIT_MASK(64)) != 0)
  1313. if (pci_set_dma_mask(bfad->pcidev, DMA_BIT_MASK(32)) != 0)
  1314. goto out_disable_device;
  1315. pci_cleanup_aer_uncorrect_error_status(pdev);
  1316. if (restart_bfa(bfad) == -1)
  1317. goto out_disable_device;
  1318. pci_enable_pcie_error_reporting(pdev);
  1319. dev_printk(KERN_WARNING, &pdev->dev,
  1320. "slot_reset completed flags: 0x%x!\n", bfad->bfad_flags);
  1321. return PCI_ERS_RESULT_RECOVERED;
  1322. out_disable_device:
  1323. pci_disable_device(pdev);
  1324. return PCI_ERS_RESULT_DISCONNECT;
  1325. }
  1326. static pci_ers_result_t
  1327. bfad_pci_mmio_enabled(struct pci_dev *pdev)
  1328. {
  1329. unsigned long flags;
  1330. struct bfad_s *bfad = pci_get_drvdata(pdev);
  1331. dev_printk(KERN_INFO, &pdev->dev, "mmio_enabled\n");
  1332. /* Fetch FW diagnostic information */
  1333. bfa_ioc_debug_save_ftrc(&bfad->bfa.ioc);
  1334. /* Cancel all pending IOs */
  1335. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1336. init_completion(&bfad->comp);
  1337. bfa_fcs_stop(&bfad->bfa_fcs);
  1338. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1339. wait_for_completion(&bfad->comp);
  1340. bfad_remove_intr(bfad);
  1341. del_timer_sync(&bfad->hal_tmo);
  1342. pci_disable_device(pdev);
  1343. return PCI_ERS_RESULT_NEED_RESET;
  1344. }
  1345. static void
  1346. bfad_pci_resume(struct pci_dev *pdev)
  1347. {
  1348. unsigned long flags;
  1349. struct bfad_s *bfad = pci_get_drvdata(pdev);
  1350. dev_printk(KERN_WARNING, &pdev->dev, "resume\n");
  1351. /* wait until the link is online */
  1352. bfad_rport_online_wait(bfad);
  1353. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1354. bfad->bfad_flags &= ~BFAD_EEH_BUSY;
  1355. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1356. }
  1357. struct pci_device_id bfad_id_table[] = {
  1358. {
  1359. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  1360. .device = BFA_PCI_DEVICE_ID_FC_8G2P,
  1361. .subvendor = PCI_ANY_ID,
  1362. .subdevice = PCI_ANY_ID,
  1363. },
  1364. {
  1365. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  1366. .device = BFA_PCI_DEVICE_ID_FC_8G1P,
  1367. .subvendor = PCI_ANY_ID,
  1368. .subdevice = PCI_ANY_ID,
  1369. },
  1370. {
  1371. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  1372. .device = BFA_PCI_DEVICE_ID_CT,
  1373. .subvendor = PCI_ANY_ID,
  1374. .subdevice = PCI_ANY_ID,
  1375. .class = (PCI_CLASS_SERIAL_FIBER << 8),
  1376. .class_mask = ~0,
  1377. },
  1378. {
  1379. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  1380. .device = BFA_PCI_DEVICE_ID_CT_FC,
  1381. .subvendor = PCI_ANY_ID,
  1382. .subdevice = PCI_ANY_ID,
  1383. .class = (PCI_CLASS_SERIAL_FIBER << 8),
  1384. .class_mask = ~0,
  1385. },
  1386. {
  1387. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  1388. .device = BFA_PCI_DEVICE_ID_CT2,
  1389. .subvendor = PCI_ANY_ID,
  1390. .subdevice = PCI_ANY_ID,
  1391. .class = (PCI_CLASS_SERIAL_FIBER << 8),
  1392. .class_mask = ~0,
  1393. },
  1394. {
  1395. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  1396. .device = BFA_PCI_DEVICE_ID_CT2_QUAD,
  1397. .subvendor = PCI_ANY_ID,
  1398. .subdevice = PCI_ANY_ID,
  1399. .class = (PCI_CLASS_SERIAL_FIBER << 8),
  1400. .class_mask = ~0,
  1401. },
  1402. {0, 0},
  1403. };
  1404. MODULE_DEVICE_TABLE(pci, bfad_id_table);
  1405. /*
  1406. * PCI error recovery handlers.
  1407. */
  1408. static struct pci_error_handlers bfad_err_handler = {
  1409. .error_detected = bfad_pci_error_detected,
  1410. .slot_reset = bfad_pci_slot_reset,
  1411. .mmio_enabled = bfad_pci_mmio_enabled,
  1412. .resume = bfad_pci_resume,
  1413. };
  1414. static struct pci_driver bfad_pci_driver = {
  1415. .name = BFAD_DRIVER_NAME,
  1416. .id_table = bfad_id_table,
  1417. .probe = bfad_pci_probe,
  1418. .remove = bfad_pci_remove,
  1419. .err_handler = &bfad_err_handler,
  1420. };
  1421. /*
  1422. * Driver module init.
  1423. */
  1424. static int __init
  1425. bfad_init(void)
  1426. {
  1427. int error = 0;
  1428. printk(KERN_INFO "Brocade BFA FC/FCOE SCSI driver - version: %s\n",
  1429. BFAD_DRIVER_VERSION);
  1430. if (num_sgpgs > 0)
  1431. num_sgpgs_parm = num_sgpgs;
  1432. error = bfad_im_module_init();
  1433. if (error) {
  1434. error = -ENOMEM;
  1435. printk(KERN_WARNING "bfad_im_module_init failure\n");
  1436. goto ext;
  1437. }
  1438. if (strcmp(FCPI_NAME, " fcpim") == 0)
  1439. supported_fc4s |= BFA_LPORT_ROLE_FCP_IM;
  1440. bfa_auto_recover = ioc_auto_recover;
  1441. bfa_fcs_rport_set_del_timeout(rport_del_timeout);
  1442. bfa_fcs_rport_set_max_logins(max_rport_logins);
  1443. error = pci_register_driver(&bfad_pci_driver);
  1444. if (error) {
  1445. printk(KERN_WARNING "pci_register_driver failure\n");
  1446. goto ext;
  1447. }
  1448. return 0;
  1449. ext:
  1450. bfad_im_module_exit();
  1451. return error;
  1452. }
  1453. /*
  1454. * Driver module exit.
  1455. */
  1456. static void __exit
  1457. bfad_exit(void)
  1458. {
  1459. pci_unregister_driver(&bfad_pci_driver);
  1460. bfad_im_module_exit();
  1461. bfad_free_fwimg();
  1462. }
  1463. /* Firmware handling */
  1464. static void
  1465. bfad_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
  1466. u32 *bfi_image_size, char *fw_name)
  1467. {
  1468. const struct firmware *fw;
  1469. if (reject_firmware(&fw, fw_name, &pdev->dev)) {
  1470. printk(KERN_ALERT "Can't locate firmware %s\n", fw_name);
  1471. *bfi_image = NULL;
  1472. goto out;
  1473. }
  1474. *bfi_image = vmalloc(fw->size);
  1475. if (NULL == *bfi_image) {
  1476. printk(KERN_ALERT "Fail to allocate buffer for fw image "
  1477. "size=%x!\n", (u32) fw->size);
  1478. goto out;
  1479. }
  1480. memcpy(*bfi_image, fw->data, fw->size);
  1481. *bfi_image_size = fw->size/sizeof(u32);
  1482. out:
  1483. release_firmware(fw);
  1484. }
  1485. static u32 *
  1486. bfad_load_fwimg(struct pci_dev *pdev)
  1487. {
  1488. if (bfa_asic_id_ct2(pdev->device)) {
  1489. if (bfi_image_ct2_size == 0)
  1490. bfad_read_firmware(pdev, &bfi_image_ct2,
  1491. &bfi_image_ct2_size, BFAD_FW_FILE_CT2);
  1492. return bfi_image_ct2;
  1493. } else if (bfa_asic_id_ct(pdev->device)) {
  1494. if (bfi_image_ct_size == 0)
  1495. bfad_read_firmware(pdev, &bfi_image_ct,
  1496. &bfi_image_ct_size, BFAD_FW_FILE_CT);
  1497. return bfi_image_ct;
  1498. } else if (bfa_asic_id_cb(pdev->device)) {
  1499. if (bfi_image_cb_size == 0)
  1500. bfad_read_firmware(pdev, &bfi_image_cb,
  1501. &bfi_image_cb_size, BFAD_FW_FILE_CB);
  1502. return bfi_image_cb;
  1503. }
  1504. return NULL;
  1505. }
  1506. static void
  1507. bfad_free_fwimg(void)
  1508. {
  1509. if (bfi_image_ct2_size && bfi_image_ct2)
  1510. vfree(bfi_image_ct2);
  1511. if (bfi_image_ct_size && bfi_image_ct)
  1512. vfree(bfi_image_ct);
  1513. if (bfi_image_cb_size && bfi_image_cb)
  1514. vfree(bfi_image_cb);
  1515. }
  1516. module_init(bfad_init);
  1517. module_exit(bfad_exit);
  1518. MODULE_LICENSE("GPL");
  1519. MODULE_DESCRIPTION("Brocade Fibre Channel HBA Driver" BFAD_PROTO_NAME);
  1520. MODULE_AUTHOR("Brocade Communications Systems, Inc.");
  1521. MODULE_VERSION(BFAD_DRIVER_VERSION);