bfad.c 46 KB

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