bfad.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. /*
  2. * Copyright (c) 2005-2009 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 "bfad_drv.h"
  23. #include "bfad_im.h"
  24. #include "bfad_tm.h"
  25. #include "bfad_ipfc.h"
  26. #include "bfad_trcmod.h"
  27. #include <fcb/bfa_fcb_vf.h>
  28. #include <fcb/bfa_fcb_rport.h>
  29. #include <fcb/bfa_fcb_port.h>
  30. #include <fcb/bfa_fcb.h>
  31. BFA_TRC_FILE(LDRV, BFAD);
  32. static DEFINE_MUTEX(bfad_mutex);
  33. LIST_HEAD(bfad_list);
  34. static int bfad_inst;
  35. int bfad_supported_fc4s;
  36. static char *host_name;
  37. static char *os_name;
  38. static char *os_patch;
  39. static int num_rports;
  40. static int num_ios;
  41. static int num_tms;
  42. static int num_fcxps;
  43. static int num_ufbufs;
  44. static int reqq_size;
  45. static int rspq_size;
  46. static int num_sgpgs;
  47. static int rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT;
  48. static int bfa_io_max_sge = BFAD_IO_MAX_SGE;
  49. static int log_level = BFA_LOG_WARNING;
  50. static int ioc_auto_recover = BFA_TRUE;
  51. static int ipfc_enable = BFA_FALSE;
  52. static int ipfc_mtu = -1;
  53. static int fdmi_enable = BFA_TRUE;
  54. int bfa_lun_queue_depth = BFAD_LUN_QUEUE_DEPTH;
  55. int bfa_linkup_delay = -1;
  56. module_param(os_name, charp, S_IRUGO | S_IWUSR);
  57. module_param(os_patch, charp, S_IRUGO | S_IWUSR);
  58. module_param(host_name, charp, S_IRUGO | S_IWUSR);
  59. module_param(num_rports, int, S_IRUGO | S_IWUSR);
  60. module_param(num_ios, int, S_IRUGO | S_IWUSR);
  61. module_param(num_tms, int, S_IRUGO | S_IWUSR);
  62. module_param(num_fcxps, int, S_IRUGO | S_IWUSR);
  63. module_param(num_ufbufs, int, S_IRUGO | S_IWUSR);
  64. module_param(reqq_size, int, S_IRUGO | S_IWUSR);
  65. module_param(rspq_size, int, S_IRUGO | S_IWUSR);
  66. module_param(num_sgpgs, int, S_IRUGO | S_IWUSR);
  67. module_param(rport_del_timeout, int, S_IRUGO | S_IWUSR);
  68. module_param(bfa_lun_queue_depth, int, S_IRUGO | S_IWUSR);
  69. module_param(bfa_io_max_sge, int, S_IRUGO | S_IWUSR);
  70. module_param(log_level, int, S_IRUGO | S_IWUSR);
  71. module_param(ioc_auto_recover, int, S_IRUGO | S_IWUSR);
  72. module_param(ipfc_enable, int, S_IRUGO | S_IWUSR);
  73. module_param(ipfc_mtu, int, S_IRUGO | S_IWUSR);
  74. module_param(fdmi_enable, int, S_IRUGO | S_IWUSR);
  75. module_param(bfa_linkup_delay, int, S_IRUGO | S_IWUSR);
  76. /*
  77. * Stores the module parm num_sgpgs value;
  78. * used to reset for bfad next instance.
  79. */
  80. static int num_sgpgs_parm;
  81. static bfa_status_t
  82. bfad_fc4_probe(struct bfad_s *bfad)
  83. {
  84. int rc;
  85. rc = bfad_im_probe(bfad);
  86. if (rc != BFA_STATUS_OK)
  87. goto ext;
  88. bfad_tm_probe(bfad);
  89. if (ipfc_enable)
  90. bfad_ipfc_probe(bfad);
  91. bfad->bfad_flags |= BFAD_FC4_PROBE_DONE;
  92. ext:
  93. return rc;
  94. }
  95. static void
  96. bfad_fc4_probe_undo(struct bfad_s *bfad)
  97. {
  98. bfad_im_probe_undo(bfad);
  99. bfad_tm_probe_undo(bfad);
  100. if (ipfc_enable)
  101. bfad_ipfc_probe_undo(bfad);
  102. bfad->bfad_flags &= ~BFAD_FC4_PROBE_DONE;
  103. }
  104. static void
  105. bfad_fc4_probe_post(struct bfad_s *bfad)
  106. {
  107. if (bfad->im)
  108. bfad_im_probe_post(bfad->im);
  109. bfad_tm_probe_post(bfad);
  110. if (ipfc_enable)
  111. bfad_ipfc_probe_post(bfad);
  112. }
  113. static bfa_status_t
  114. bfad_fc4_port_new(struct bfad_s *bfad, struct bfad_port_s *port, int roles)
  115. {
  116. int rc = BFA_STATUS_FAILED;
  117. if (roles & BFA_PORT_ROLE_FCP_IM)
  118. rc = bfad_im_port_new(bfad, port);
  119. if (rc != BFA_STATUS_OK)
  120. goto ext;
  121. if (roles & BFA_PORT_ROLE_FCP_TM)
  122. rc = bfad_tm_port_new(bfad, port);
  123. if (rc != BFA_STATUS_OK)
  124. goto ext;
  125. if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
  126. rc = bfad_ipfc_port_new(bfad, port, port->pvb_type);
  127. ext:
  128. return rc;
  129. }
  130. static void
  131. bfad_fc4_port_delete(struct bfad_s *bfad, struct bfad_port_s *port, int roles)
  132. {
  133. if (roles & BFA_PORT_ROLE_FCP_IM)
  134. bfad_im_port_delete(bfad, port);
  135. if (roles & BFA_PORT_ROLE_FCP_TM)
  136. bfad_tm_port_delete(bfad, port);
  137. if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
  138. bfad_ipfc_port_delete(bfad, port);
  139. }
  140. /**
  141. * BFA callbacks
  142. */
  143. void
  144. bfad_hcb_comp(void *arg, bfa_status_t status)
  145. {
  146. struct bfad_hal_comp *fcomp = (struct bfad_hal_comp *)arg;
  147. fcomp->status = status;
  148. complete(&fcomp->comp);
  149. }
  150. /**
  151. * bfa_init callback
  152. */
  153. void
  154. bfa_cb_init(void *drv, bfa_status_t init_status)
  155. {
  156. struct bfad_s *bfad = drv;
  157. if (init_status == BFA_STATUS_OK) {
  158. bfad->bfad_flags |= BFAD_HAL_INIT_DONE;
  159. /* If BFAD_HAL_INIT_FAIL flag is set:
  160. * Wake up the kernel thread to start
  161. * the bfad operations after HAL init done
  162. */
  163. if ((bfad->bfad_flags & BFAD_HAL_INIT_FAIL)) {
  164. bfad->bfad_flags &= ~BFAD_HAL_INIT_FAIL;
  165. wake_up_process(bfad->bfad_tsk);
  166. }
  167. }
  168. complete(&bfad->comp);
  169. }
  170. /**
  171. * BFA_FCS callbacks
  172. */
  173. static struct bfad_port_s *
  174. bfad_get_drv_port(struct bfad_s *bfad, struct bfad_vf_s *vf_drv,
  175. struct bfad_vport_s *vp_drv)
  176. {
  177. return (vp_drv) ? (&(vp_drv)->drv_port)
  178. : ((vf_drv) ? (&(vf_drv)->base_port) : (&(bfad)->pport));
  179. }
  180. struct bfad_port_s *
  181. bfa_fcb_port_new(struct bfad_s *bfad, struct bfa_fcs_port_s *port,
  182. enum bfa_port_role roles, struct bfad_vf_s *vf_drv,
  183. struct bfad_vport_s *vp_drv)
  184. {
  185. bfa_status_t rc;
  186. struct bfad_port_s *port_drv;
  187. if (!vp_drv && !vf_drv) {
  188. port_drv = &bfad->pport;
  189. port_drv->pvb_type = BFAD_PORT_PHYS_BASE;
  190. } else if (!vp_drv && vf_drv) {
  191. port_drv = &vf_drv->base_port;
  192. port_drv->pvb_type = BFAD_PORT_VF_BASE;
  193. } else if (vp_drv && !vf_drv) {
  194. port_drv = &vp_drv->drv_port;
  195. port_drv->pvb_type = BFAD_PORT_PHYS_VPORT;
  196. } else {
  197. port_drv = &vp_drv->drv_port;
  198. port_drv->pvb_type = BFAD_PORT_VF_VPORT;
  199. }
  200. port_drv->fcs_port = port;
  201. port_drv->roles = roles;
  202. rc = bfad_fc4_port_new(bfad, port_drv, roles);
  203. if (rc != BFA_STATUS_OK) {
  204. bfad_fc4_port_delete(bfad, port_drv, roles);
  205. port_drv = NULL;
  206. }
  207. return port_drv;
  208. }
  209. void
  210. bfa_fcb_port_delete(struct bfad_s *bfad, enum bfa_port_role roles,
  211. struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv)
  212. {
  213. struct bfad_port_s *port_drv;
  214. /*
  215. * this will be only called from rmmod context
  216. */
  217. if (vp_drv && !vp_drv->comp_del) {
  218. port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv);
  219. bfa_trc(bfad, roles);
  220. bfad_fc4_port_delete(bfad, port_drv, roles);
  221. }
  222. }
  223. void
  224. bfa_fcb_port_online(struct bfad_s *bfad, enum bfa_port_role roles,
  225. struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv)
  226. {
  227. struct bfad_port_s *port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv);
  228. if (roles & BFA_PORT_ROLE_FCP_IM)
  229. bfad_im_port_online(bfad, port_drv);
  230. if (roles & BFA_PORT_ROLE_FCP_TM)
  231. bfad_tm_port_online(bfad, port_drv);
  232. if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
  233. bfad_ipfc_port_online(bfad, port_drv);
  234. bfad->bfad_flags |= BFAD_PORT_ONLINE;
  235. }
  236. void
  237. bfa_fcb_port_offline(struct bfad_s *bfad, enum bfa_port_role roles,
  238. struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv)
  239. {
  240. struct bfad_port_s *port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv);
  241. if (roles & BFA_PORT_ROLE_FCP_IM)
  242. bfad_im_port_offline(bfad, port_drv);
  243. if (roles & BFA_PORT_ROLE_FCP_TM)
  244. bfad_tm_port_offline(bfad, port_drv);
  245. if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
  246. bfad_ipfc_port_offline(bfad, port_drv);
  247. }
  248. void
  249. bfa_fcb_vport_delete(struct bfad_vport_s *vport_drv)
  250. {
  251. if (vport_drv->comp_del) {
  252. complete(vport_drv->comp_del);
  253. return;
  254. }
  255. kfree(vport_drv);
  256. }
  257. /**
  258. * FCS RPORT alloc callback, after successful PLOGI by FCS
  259. */
  260. bfa_status_t
  261. bfa_fcb_rport_alloc(struct bfad_s *bfad, struct bfa_fcs_rport_s **rport,
  262. struct bfad_rport_s **rport_drv)
  263. {
  264. bfa_status_t rc = BFA_STATUS_OK;
  265. *rport_drv = kzalloc(sizeof(struct bfad_rport_s), GFP_ATOMIC);
  266. if (*rport_drv == NULL) {
  267. rc = BFA_STATUS_ENOMEM;
  268. goto ext;
  269. }
  270. *rport = &(*rport_drv)->fcs_rport;
  271. ext:
  272. return rc;
  273. }
  274. void
  275. bfad_hal_mem_release(struct bfad_s *bfad)
  276. {
  277. int i;
  278. struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
  279. struct bfa_mem_elem_s *meminfo_elem;
  280. for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
  281. meminfo_elem = &hal_meminfo->meminfo[i];
  282. if (meminfo_elem->kva != NULL) {
  283. switch (meminfo_elem->mem_type) {
  284. case BFA_MEM_TYPE_KVA:
  285. vfree(meminfo_elem->kva);
  286. break;
  287. case BFA_MEM_TYPE_DMA:
  288. dma_free_coherent(&bfad->pcidev->dev,
  289. meminfo_elem->mem_len,
  290. meminfo_elem->kva,
  291. (dma_addr_t) meminfo_elem->dma);
  292. break;
  293. default:
  294. bfa_assert(0);
  295. break;
  296. }
  297. }
  298. }
  299. memset(hal_meminfo, 0, sizeof(struct bfa_meminfo_s));
  300. }
  301. void
  302. bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg)
  303. {
  304. if (num_rports > 0)
  305. bfa_cfg->fwcfg.num_rports = num_rports;
  306. if (num_ios > 0)
  307. bfa_cfg->fwcfg.num_ioim_reqs = num_ios;
  308. if (num_tms > 0)
  309. bfa_cfg->fwcfg.num_tskim_reqs = num_tms;
  310. if (num_fcxps > 0)
  311. bfa_cfg->fwcfg.num_fcxp_reqs = num_fcxps;
  312. if (num_ufbufs > 0)
  313. bfa_cfg->fwcfg.num_uf_bufs = num_ufbufs;
  314. if (reqq_size > 0)
  315. bfa_cfg->drvcfg.num_reqq_elems = reqq_size;
  316. if (rspq_size > 0)
  317. bfa_cfg->drvcfg.num_rspq_elems = rspq_size;
  318. if (num_sgpgs > 0)
  319. bfa_cfg->drvcfg.num_sgpgs = num_sgpgs;
  320. /*
  321. * populate the hal values back to the driver for sysfs use.
  322. * otherwise, the default values will be shown as 0 in sysfs
  323. */
  324. num_rports = bfa_cfg->fwcfg.num_rports;
  325. num_ios = bfa_cfg->fwcfg.num_ioim_reqs;
  326. num_tms = bfa_cfg->fwcfg.num_tskim_reqs;
  327. num_fcxps = bfa_cfg->fwcfg.num_fcxp_reqs;
  328. num_ufbufs = bfa_cfg->fwcfg.num_uf_bufs;
  329. reqq_size = bfa_cfg->drvcfg.num_reqq_elems;
  330. rspq_size = bfa_cfg->drvcfg.num_rspq_elems;
  331. num_sgpgs = bfa_cfg->drvcfg.num_sgpgs;
  332. }
  333. bfa_status_t
  334. bfad_hal_mem_alloc(struct bfad_s *bfad)
  335. {
  336. struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
  337. struct bfa_mem_elem_s *meminfo_elem;
  338. bfa_status_t rc = BFA_STATUS_OK;
  339. dma_addr_t phys_addr;
  340. int retry_count = 0;
  341. int reset_value = 1;
  342. int min_num_sgpgs = 512;
  343. void *kva;
  344. int i;
  345. bfa_cfg_get_default(&bfad->ioc_cfg);
  346. retry:
  347. bfad_update_hal_cfg(&bfad->ioc_cfg);
  348. bfad->cfg_data.ioc_queue_depth = bfad->ioc_cfg.fwcfg.num_ioim_reqs;
  349. bfa_cfg_get_meminfo(&bfad->ioc_cfg, hal_meminfo);
  350. for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
  351. meminfo_elem = &hal_meminfo->meminfo[i];
  352. switch (meminfo_elem->mem_type) {
  353. case BFA_MEM_TYPE_KVA:
  354. kva = vmalloc(meminfo_elem->mem_len);
  355. if (kva == NULL) {
  356. bfad_hal_mem_release(bfad);
  357. rc = BFA_STATUS_ENOMEM;
  358. goto ext;
  359. }
  360. memset(kva, 0, meminfo_elem->mem_len);
  361. meminfo_elem->kva = kva;
  362. break;
  363. case BFA_MEM_TYPE_DMA:
  364. kva = dma_alloc_coherent(&bfad->pcidev->dev,
  365. meminfo_elem->mem_len,
  366. &phys_addr, GFP_KERNEL);
  367. if (kva == NULL) {
  368. bfad_hal_mem_release(bfad);
  369. /*
  370. * If we cannot allocate with default
  371. * num_sgpages try with half the value.
  372. */
  373. if (num_sgpgs > min_num_sgpgs) {
  374. printk(KERN_INFO "bfad[%d]: memory"
  375. " allocation failed with"
  376. " num_sgpgs: %d\n",
  377. bfad->inst_no, num_sgpgs);
  378. nextLowerInt(&num_sgpgs);
  379. printk(KERN_INFO "bfad[%d]: trying to"
  380. " allocate memory with"
  381. " num_sgpgs: %d\n",
  382. bfad->inst_no, num_sgpgs);
  383. retry_count++;
  384. goto retry;
  385. } else {
  386. if (num_sgpgs_parm > 0)
  387. num_sgpgs = num_sgpgs_parm;
  388. else {
  389. reset_value =
  390. (1 << retry_count);
  391. num_sgpgs *= reset_value;
  392. }
  393. rc = BFA_STATUS_ENOMEM;
  394. goto ext;
  395. }
  396. }
  397. if (num_sgpgs_parm > 0)
  398. num_sgpgs = num_sgpgs_parm;
  399. else {
  400. reset_value = (1 << retry_count);
  401. num_sgpgs *= reset_value;
  402. }
  403. memset(kva, 0, meminfo_elem->mem_len);
  404. meminfo_elem->kva = kva;
  405. meminfo_elem->dma = phys_addr;
  406. break;
  407. default:
  408. break;
  409. }
  410. }
  411. ext:
  412. return rc;
  413. }
  414. /**
  415. * Create a vport under a vf.
  416. */
  417. bfa_status_t
  418. bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
  419. struct bfa_port_cfg_s *port_cfg)
  420. {
  421. struct bfad_vport_s *vport;
  422. int rc = BFA_STATUS_OK;
  423. unsigned long flags;
  424. struct completion fcomp;
  425. vport = kzalloc(sizeof(struct bfad_vport_s), GFP_KERNEL);
  426. if (!vport) {
  427. rc = BFA_STATUS_ENOMEM;
  428. goto ext;
  429. }
  430. vport->drv_port.bfad = bfad;
  431. spin_lock_irqsave(&bfad->bfad_lock, flags);
  432. rc = bfa_fcs_vport_create(&vport->fcs_vport, &bfad->bfa_fcs, vf_id,
  433. port_cfg, vport);
  434. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  435. if (rc != BFA_STATUS_OK)
  436. goto ext_free_vport;
  437. if (port_cfg->roles & BFA_PORT_ROLE_FCP_IM) {
  438. rc = bfad_im_scsi_host_alloc(bfad, vport->drv_port.im_port);
  439. if (rc != BFA_STATUS_OK)
  440. goto ext_free_fcs_vport;
  441. }
  442. spin_lock_irqsave(&bfad->bfad_lock, flags);
  443. bfa_fcs_vport_start(&vport->fcs_vport);
  444. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  445. return BFA_STATUS_OK;
  446. ext_free_fcs_vport:
  447. spin_lock_irqsave(&bfad->bfad_lock, flags);
  448. vport->comp_del = &fcomp;
  449. init_completion(vport->comp_del);
  450. bfa_fcs_vport_delete(&vport->fcs_vport);
  451. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  452. wait_for_completion(vport->comp_del);
  453. ext_free_vport:
  454. kfree(vport);
  455. ext:
  456. return rc;
  457. }
  458. /**
  459. * Create a vf and its base vport implicitely.
  460. */
  461. bfa_status_t
  462. bfad_vf_create(struct bfad_s *bfad, u16 vf_id,
  463. struct bfa_port_cfg_s *port_cfg)
  464. {
  465. struct bfad_vf_s *vf;
  466. int rc = BFA_STATUS_OK;
  467. vf = kzalloc(sizeof(struct bfad_vf_s), GFP_KERNEL);
  468. if (!vf) {
  469. rc = BFA_STATUS_FAILED;
  470. goto ext;
  471. }
  472. rc = bfa_fcs_vf_create(&vf->fcs_vf, &bfad->bfa_fcs, vf_id, port_cfg,
  473. vf);
  474. if (rc != BFA_STATUS_OK)
  475. kfree(vf);
  476. ext:
  477. return rc;
  478. }
  479. void
  480. bfad_bfa_tmo(unsigned long data)
  481. {
  482. struct bfad_s *bfad = (struct bfad_s *)data;
  483. unsigned long flags;
  484. struct list_head doneq;
  485. spin_lock_irqsave(&bfad->bfad_lock, flags);
  486. bfa_timer_tick(&bfad->bfa);
  487. bfa_comp_deq(&bfad->bfa, &doneq);
  488. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  489. if (!list_empty(&doneq)) {
  490. bfa_comp_process(&bfad->bfa, &doneq);
  491. spin_lock_irqsave(&bfad->bfad_lock, flags);
  492. bfa_comp_free(&bfad->bfa, &doneq);
  493. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  494. }
  495. mod_timer(&bfad->hal_tmo, jiffies + msecs_to_jiffies(BFA_TIMER_FREQ));
  496. }
  497. void
  498. bfad_init_timer(struct bfad_s *bfad)
  499. {
  500. init_timer(&bfad->hal_tmo);
  501. bfad->hal_tmo.function = bfad_bfa_tmo;
  502. bfad->hal_tmo.data = (unsigned long)bfad;
  503. mod_timer(&bfad->hal_tmo, jiffies + msecs_to_jiffies(BFA_TIMER_FREQ));
  504. }
  505. int
  506. bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad)
  507. {
  508. unsigned long bar0_len;
  509. int rc = -ENODEV;
  510. if (pci_enable_device(pdev)) {
  511. BFA_PRINTF(BFA_ERR, "pci_enable_device fail %p\n", pdev);
  512. goto out;
  513. }
  514. if (pci_request_regions(pdev, BFAD_DRIVER_NAME))
  515. goto out_disable_device;
  516. pci_set_master(pdev);
  517. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
  518. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
  519. BFA_PRINTF(BFA_ERR, "pci_set_dma_mask fail %p\n", pdev);
  520. goto out_release_region;
  521. }
  522. bfad->pci_bar0_map = pci_resource_start(pdev, 0);
  523. bar0_len = pci_resource_len(pdev, 0);
  524. bfad->pci_bar0_kva = ioremap(bfad->pci_bar0_map, bar0_len);
  525. if (bfad->pci_bar0_kva == NULL) {
  526. BFA_PRINTF(BFA_ERR, "Fail to map bar0\n");
  527. goto out_release_region;
  528. }
  529. bfad->hal_pcidev.pci_slot = PCI_SLOT(pdev->devfn);
  530. bfad->hal_pcidev.pci_func = PCI_FUNC(pdev->devfn);
  531. bfad->hal_pcidev.pci_bar_kva = bfad->pci_bar0_kva;
  532. bfad->hal_pcidev.device_id = pdev->device;
  533. bfad->pci_name = pci_name(pdev);
  534. bfad->pci_attr.vendor_id = pdev->vendor;
  535. bfad->pci_attr.device_id = pdev->device;
  536. bfad->pci_attr.ssid = pdev->subsystem_device;
  537. bfad->pci_attr.ssvid = pdev->subsystem_vendor;
  538. bfad->pci_attr.pcifn = PCI_FUNC(pdev->devfn);
  539. bfad->pcidev = pdev;
  540. return 0;
  541. out_release_region:
  542. pci_release_regions(pdev);
  543. out_disable_device:
  544. pci_disable_device(pdev);
  545. out:
  546. return rc;
  547. }
  548. void
  549. bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad)
  550. {
  551. #if defined(__ia64__)
  552. pci_iounmap(pdev, bfad->pci_bar0_kva);
  553. #else
  554. iounmap(bfad->pci_bar0_kva);
  555. #endif
  556. pci_release_regions(pdev);
  557. pci_disable_device(pdev);
  558. pci_set_drvdata(pdev, NULL);
  559. }
  560. void
  561. bfad_fcs_port_cfg(struct bfad_s *bfad)
  562. {
  563. struct bfa_port_cfg_s port_cfg;
  564. struct bfa_pport_attr_s attr;
  565. char symname[BFA_SYMNAME_MAXLEN];
  566. sprintf(symname, "%s-%d", BFAD_DRIVER_NAME, bfad->inst_no);
  567. memcpy(port_cfg.sym_name.symname, symname, strlen(symname));
  568. bfa_fcport_get_attr(&bfad->bfa, &attr);
  569. port_cfg.nwwn = attr.nwwn;
  570. port_cfg.pwwn = attr.pwwn;
  571. bfa_fcs_cfg_base_port(&bfad->bfa_fcs, &port_cfg);
  572. }
  573. bfa_status_t
  574. bfad_drv_init(struct bfad_s *bfad)
  575. {
  576. bfa_status_t rc;
  577. unsigned long flags;
  578. struct bfa_fcs_driver_info_s driver_info;
  579. bfad->cfg_data.rport_del_timeout = rport_del_timeout;
  580. bfad->cfg_data.lun_queue_depth = bfa_lun_queue_depth;
  581. bfad->cfg_data.io_max_sge = bfa_io_max_sge;
  582. bfad->cfg_data.binding_method = FCP_PWWN_BINDING;
  583. rc = bfad_hal_mem_alloc(bfad);
  584. if (rc != BFA_STATUS_OK) {
  585. printk(KERN_WARNING "bfad%d bfad_hal_mem_alloc failure\n",
  586. bfad->inst_no);
  587. printk(KERN_WARNING
  588. "Not enough memory to attach all Brocade HBA ports,"
  589. " System may need more memory.\n");
  590. goto out_hal_mem_alloc_failure;
  591. }
  592. bfa_init_log(&bfad->bfa, bfad->logmod);
  593. bfa_init_trc(&bfad->bfa, bfad->trcmod);
  594. bfa_init_aen(&bfad->bfa, bfad->aen);
  595. memset(bfad->file_map, 0, sizeof(bfad->file_map));
  596. bfa_init_plog(&bfad->bfa, &bfad->plog_buf);
  597. bfa_plog_init(&bfad->plog_buf);
  598. bfa_plog_str(&bfad->plog_buf, BFA_PL_MID_DRVR, BFA_PL_EID_DRIVER_START,
  599. 0, "Driver Attach");
  600. bfa_attach(&bfad->bfa, bfad, &bfad->ioc_cfg, &bfad->meminfo,
  601. &bfad->hal_pcidev);
  602. init_completion(&bfad->comp);
  603. /*
  604. * Enable Interrupt and wait bfa_init completion
  605. */
  606. if (bfad_setup_intr(bfad)) {
  607. printk(KERN_WARNING "bfad%d: bfad_setup_intr failed\n",
  608. bfad->inst_no);
  609. goto out_setup_intr_failure;
  610. }
  611. spin_lock_irqsave(&bfad->bfad_lock, flags);
  612. bfa_init(&bfad->bfa);
  613. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  614. /*
  615. * Set up interrupt handler for each vectors
  616. */
  617. if ((bfad->bfad_flags & BFAD_MSIX_ON)
  618. && bfad_install_msix_handler(bfad)) {
  619. printk(KERN_WARNING "%s: install_msix failed, bfad%d\n",
  620. __func__, bfad->inst_no);
  621. }
  622. bfad_init_timer(bfad);
  623. wait_for_completion(&bfad->comp);
  624. memset(&driver_info, 0, sizeof(driver_info));
  625. strncpy(driver_info.version, BFAD_DRIVER_VERSION,
  626. sizeof(driver_info.version) - 1);
  627. if (host_name)
  628. strncpy(driver_info.host_machine_name, host_name,
  629. sizeof(driver_info.host_machine_name) - 1);
  630. if (os_name)
  631. strncpy(driver_info.host_os_name, os_name,
  632. sizeof(driver_info.host_os_name) - 1);
  633. if (os_patch)
  634. strncpy(driver_info.host_os_patch, os_patch,
  635. sizeof(driver_info.host_os_patch) - 1);
  636. strncpy(driver_info.os_device_name, bfad->pci_name,
  637. sizeof(driver_info.os_device_name - 1));
  638. /*
  639. * FCS INIT
  640. */
  641. spin_lock_irqsave(&bfad->bfad_lock, flags);
  642. bfa_fcs_log_init(&bfad->bfa_fcs, bfad->logmod);
  643. bfa_fcs_trc_init(&bfad->bfa_fcs, bfad->trcmod);
  644. bfa_fcs_aen_init(&bfad->bfa_fcs, bfad->aen);
  645. bfa_fcs_attach(&bfad->bfa_fcs, &bfad->bfa, bfad, BFA_FALSE);
  646. /* Do FCS init only when HAL init is done */
  647. if ((bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
  648. bfa_fcs_init(&bfad->bfa_fcs);
  649. bfad->bfad_flags |= BFAD_FCS_INIT_DONE;
  650. }
  651. bfa_fcs_driver_info_init(&bfad->bfa_fcs, &driver_info);
  652. bfa_fcs_set_fdmi_param(&bfad->bfa_fcs, fdmi_enable);
  653. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  654. bfad->bfad_flags |= BFAD_DRV_INIT_DONE;
  655. return BFA_STATUS_OK;
  656. out_setup_intr_failure:
  657. bfa_detach(&bfad->bfa);
  658. bfad_hal_mem_release(bfad);
  659. out_hal_mem_alloc_failure:
  660. return BFA_STATUS_FAILED;
  661. }
  662. void
  663. bfad_drv_uninit(struct bfad_s *bfad)
  664. {
  665. unsigned long flags;
  666. spin_lock_irqsave(&bfad->bfad_lock, flags);
  667. init_completion(&bfad->comp);
  668. bfa_stop(&bfad->bfa);
  669. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  670. wait_for_completion(&bfad->comp);
  671. del_timer_sync(&bfad->hal_tmo);
  672. bfa_isr_disable(&bfad->bfa);
  673. bfa_detach(&bfad->bfa);
  674. bfad_remove_intr(bfad);
  675. bfad_hal_mem_release(bfad);
  676. bfad->bfad_flags &= ~BFAD_DRV_INIT_DONE;
  677. }
  678. void
  679. bfad_drv_start(struct bfad_s *bfad)
  680. {
  681. unsigned long flags;
  682. spin_lock_irqsave(&bfad->bfad_lock, flags);
  683. bfa_start(&bfad->bfa);
  684. bfa_fcs_start(&bfad->bfa_fcs);
  685. bfad->bfad_flags |= BFAD_HAL_START_DONE;
  686. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  687. bfad_fc4_probe_post(bfad);
  688. }
  689. void
  690. bfad_drv_stop(struct bfad_s *bfad)
  691. {
  692. unsigned long flags;
  693. spin_lock_irqsave(&bfad->bfad_lock, flags);
  694. init_completion(&bfad->comp);
  695. bfad->pport.flags |= BFAD_PORT_DELETE;
  696. bfa_fcs_exit(&bfad->bfa_fcs);
  697. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  698. wait_for_completion(&bfad->comp);
  699. spin_lock_irqsave(&bfad->bfad_lock, flags);
  700. init_completion(&bfad->comp);
  701. bfa_stop(&bfad->bfa);
  702. bfad->bfad_flags &= ~BFAD_HAL_START_DONE;
  703. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  704. wait_for_completion(&bfad->comp);
  705. }
  706. bfa_status_t
  707. bfad_cfg_pport(struct bfad_s *bfad, enum bfa_port_role role)
  708. {
  709. int rc = BFA_STATUS_OK;
  710. /*
  711. * Allocate scsi_host for the physical port
  712. */
  713. if ((bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IM)
  714. && (role & BFA_PORT_ROLE_FCP_IM)) {
  715. if (bfad->pport.im_port == NULL) {
  716. rc = BFA_STATUS_FAILED;
  717. goto out;
  718. }
  719. rc = bfad_im_scsi_host_alloc(bfad, bfad->pport.im_port);
  720. if (rc != BFA_STATUS_OK)
  721. goto out;
  722. bfad->pport.roles |= BFA_PORT_ROLE_FCP_IM;
  723. }
  724. bfad->bfad_flags |= BFAD_CFG_PPORT_DONE;
  725. out:
  726. return rc;
  727. }
  728. void
  729. bfad_uncfg_pport(struct bfad_s *bfad)
  730. {
  731. if ((bfad->pport.roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable) {
  732. bfad_ipfc_port_delete(bfad, &bfad->pport);
  733. bfad->pport.roles &= ~BFA_PORT_ROLE_FCP_IPFC;
  734. }
  735. if ((bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IM)
  736. && (bfad->pport.roles & BFA_PORT_ROLE_FCP_IM)) {
  737. bfad_im_scsi_host_free(bfad, bfad->pport.im_port);
  738. bfad_im_port_clean(bfad->pport.im_port);
  739. kfree(bfad->pport.im_port);
  740. bfad->pport.roles &= ~BFA_PORT_ROLE_FCP_IM;
  741. }
  742. bfad->bfad_flags &= ~BFAD_CFG_PPORT_DONE;
  743. }
  744. void
  745. bfad_drv_log_level_set(struct bfad_s *bfad)
  746. {
  747. if (log_level > BFA_LOG_INVALID && log_level <= BFA_LOG_LEVEL_MAX)
  748. bfa_log_set_level_all(&bfad->log_data, log_level);
  749. }
  750. bfa_status_t
  751. bfad_start_ops(struct bfad_s *bfad)
  752. {
  753. int retval;
  754. /* PPORT FCS config */
  755. bfad_fcs_port_cfg(bfad);
  756. retval = bfad_cfg_pport(bfad, BFA_PORT_ROLE_FCP_IM);
  757. if (retval != BFA_STATUS_OK)
  758. goto out_cfg_pport_failure;
  759. /* BFAD level FC4 (IM/TM/IPFC) specific resource allocation */
  760. retval = bfad_fc4_probe(bfad);
  761. if (retval != BFA_STATUS_OK) {
  762. printk(KERN_WARNING "bfad_fc4_probe failed\n");
  763. goto out_fc4_probe_failure;
  764. }
  765. bfad_drv_start(bfad);
  766. /*
  767. * If bfa_linkup_delay is set to -1 default; try to retrive the
  768. * value using the bfad_os_get_linkup_delay(); else use the
  769. * passed in module param value as the bfa_linkup_delay.
  770. */
  771. if (bfa_linkup_delay < 0) {
  772. bfa_linkup_delay = bfad_os_get_linkup_delay(bfad);
  773. bfad_os_rport_online_wait(bfad);
  774. bfa_linkup_delay = -1;
  775. } else {
  776. bfad_os_rport_online_wait(bfad);
  777. }
  778. bfa_log(bfad->logmod, BFA_LOG_LINUX_DEVICE_CLAIMED, bfad->pci_name);
  779. return BFA_STATUS_OK;
  780. out_fc4_probe_failure:
  781. bfad_fc4_probe_undo(bfad);
  782. bfad_uncfg_pport(bfad);
  783. out_cfg_pport_failure:
  784. return BFA_STATUS_FAILED;
  785. }
  786. int
  787. bfad_worker (void *ptr)
  788. {
  789. struct bfad_s *bfad;
  790. unsigned long flags;
  791. bfad = (struct bfad_s *)ptr;
  792. while (!kthread_should_stop()) {
  793. /* Check if the FCS init is done from bfad_drv_init;
  794. * if not done do FCS init and set the flag.
  795. */
  796. if (!(bfad->bfad_flags & BFAD_FCS_INIT_DONE)) {
  797. spin_lock_irqsave(&bfad->bfad_lock, flags);
  798. bfa_fcs_init(&bfad->bfa_fcs);
  799. bfad->bfad_flags |= BFAD_FCS_INIT_DONE;
  800. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  801. }
  802. /* Start the bfad operations after HAL init done */
  803. bfad_start_ops(bfad);
  804. spin_lock_irqsave(&bfad->bfad_lock, flags);
  805. bfad->bfad_tsk = NULL;
  806. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  807. break;
  808. }
  809. return 0;
  810. }
  811. /*
  812. * PCI_entry PCI driver entries * {
  813. */
  814. /**
  815. * PCI probe entry.
  816. */
  817. int
  818. bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
  819. {
  820. struct bfad_s *bfad;
  821. int error = -ENODEV, retval;
  822. /*
  823. * For single port cards - only claim function 0
  824. */
  825. if ((pdev->device == BFA_PCI_DEVICE_ID_FC_8G1P)
  826. && (PCI_FUNC(pdev->devfn) != 0))
  827. return -ENODEV;
  828. BFA_TRACE(BFA_INFO, "bfad_pci_probe entry");
  829. bfad = kzalloc(sizeof(struct bfad_s), GFP_KERNEL);
  830. if (!bfad) {
  831. error = -ENOMEM;
  832. goto out;
  833. }
  834. bfad->trcmod = kzalloc(sizeof(struct bfa_trc_mod_s), GFP_KERNEL);
  835. if (!bfad->trcmod) {
  836. printk(KERN_WARNING "Error alloc trace buffer!\n");
  837. error = -ENOMEM;
  838. goto out_alloc_trace_failure;
  839. }
  840. /*
  841. * LOG/TRACE INIT
  842. */
  843. bfa_trc_init(bfad->trcmod);
  844. bfa_trc(bfad, bfad_inst);
  845. bfad->logmod = &bfad->log_data;
  846. bfa_log_init(bfad->logmod, (char *)pci_name(pdev), bfa_os_printf);
  847. bfad_drv_log_level_set(bfad);
  848. bfad->aen = &bfad->aen_buf;
  849. if (!(bfad_load_fwimg(pdev))) {
  850. printk(KERN_WARNING "bfad_load_fwimg failure!\n");
  851. kfree(bfad->trcmod);
  852. goto out_alloc_trace_failure;
  853. }
  854. retval = bfad_pci_init(pdev, bfad);
  855. if (retval) {
  856. printk(KERN_WARNING "bfad_pci_init failure!\n");
  857. error = retval;
  858. goto out_pci_init_failure;
  859. }
  860. mutex_lock(&bfad_mutex);
  861. bfad->inst_no = bfad_inst++;
  862. list_add_tail(&bfad->list_entry, &bfad_list);
  863. mutex_unlock(&bfad_mutex);
  864. spin_lock_init(&bfad->bfad_lock);
  865. pci_set_drvdata(pdev, bfad);
  866. bfad->ref_count = 0;
  867. bfad->pport.bfad = bfad;
  868. bfad->bfad_tsk = kthread_create(bfad_worker, (void *) bfad, "%s",
  869. "bfad_worker");
  870. if (IS_ERR(bfad->bfad_tsk)) {
  871. printk(KERN_INFO "bfad[%d]: Kernel thread"
  872. " creation failed!\n",
  873. bfad->inst_no);
  874. goto out_kthread_create_failure;
  875. }
  876. retval = bfad_drv_init(bfad);
  877. if (retval != BFA_STATUS_OK)
  878. goto out_drv_init_failure;
  879. if (!(bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
  880. bfad->bfad_flags |= BFAD_HAL_INIT_FAIL;
  881. printk(KERN_WARNING "bfad%d: hal init failed\n", bfad->inst_no);
  882. goto ok;
  883. }
  884. retval = bfad_start_ops(bfad);
  885. if (retval != BFA_STATUS_OK)
  886. goto out_start_ops_failure;
  887. kthread_stop(bfad->bfad_tsk);
  888. bfad->bfad_tsk = NULL;
  889. ok:
  890. return 0;
  891. out_start_ops_failure:
  892. bfad_drv_uninit(bfad);
  893. out_drv_init_failure:
  894. kthread_stop(bfad->bfad_tsk);
  895. out_kthread_create_failure:
  896. mutex_lock(&bfad_mutex);
  897. bfad_inst--;
  898. list_del(&bfad->list_entry);
  899. mutex_unlock(&bfad_mutex);
  900. bfad_pci_uninit(pdev, bfad);
  901. out_pci_init_failure:
  902. kfree(bfad->trcmod);
  903. out_alloc_trace_failure:
  904. kfree(bfad);
  905. out:
  906. return error;
  907. }
  908. /**
  909. * PCI remove entry.
  910. */
  911. void
  912. bfad_pci_remove(struct pci_dev *pdev)
  913. {
  914. struct bfad_s *bfad = pci_get_drvdata(pdev);
  915. unsigned long flags;
  916. bfa_trc(bfad, bfad->inst_no);
  917. spin_lock_irqsave(&bfad->bfad_lock, flags);
  918. if (bfad->bfad_tsk != NULL)
  919. kthread_stop(bfad->bfad_tsk);
  920. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  921. if ((bfad->bfad_flags & BFAD_DRV_INIT_DONE)
  922. && !(bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
  923. spin_lock_irqsave(&bfad->bfad_lock, flags);
  924. init_completion(&bfad->comp);
  925. bfa_stop(&bfad->bfa);
  926. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  927. wait_for_completion(&bfad->comp);
  928. bfad_remove_intr(bfad);
  929. del_timer_sync(&bfad->hal_tmo);
  930. goto hal_detach;
  931. } else if (!(bfad->bfad_flags & BFAD_DRV_INIT_DONE)) {
  932. goto remove_sysfs;
  933. }
  934. if (bfad->bfad_flags & BFAD_HAL_START_DONE) {
  935. bfad_drv_stop(bfad);
  936. } else if (bfad->bfad_flags & BFAD_DRV_INIT_DONE) {
  937. /* Invoking bfa_stop() before bfa_detach
  938. * when HAL and DRV init are success
  939. * but HAL start did not occur.
  940. */
  941. spin_lock_irqsave(&bfad->bfad_lock, flags);
  942. init_completion(&bfad->comp);
  943. bfa_stop(&bfad->bfa);
  944. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  945. wait_for_completion(&bfad->comp);
  946. }
  947. bfad_remove_intr(bfad);
  948. del_timer_sync(&bfad->hal_tmo);
  949. if (bfad->bfad_flags & BFAD_FC4_PROBE_DONE)
  950. bfad_fc4_probe_undo(bfad);
  951. if (bfad->bfad_flags & BFAD_CFG_PPORT_DONE)
  952. bfad_uncfg_pport(bfad);
  953. hal_detach:
  954. spin_lock_irqsave(&bfad->bfad_lock, flags);
  955. bfa_detach(&bfad->bfa);
  956. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  957. bfad_hal_mem_release(bfad);
  958. remove_sysfs:
  959. mutex_lock(&bfad_mutex);
  960. bfad_inst--;
  961. list_del(&bfad->list_entry);
  962. mutex_unlock(&bfad_mutex);
  963. bfad_pci_uninit(pdev, bfad);
  964. kfree(bfad->trcmod);
  965. kfree(bfad);
  966. }
  967. static struct pci_device_id bfad_id_table[] = {
  968. {
  969. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  970. .device = BFA_PCI_DEVICE_ID_FC_8G2P,
  971. .subvendor = PCI_ANY_ID,
  972. .subdevice = PCI_ANY_ID,
  973. },
  974. {
  975. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  976. .device = BFA_PCI_DEVICE_ID_FC_8G1P,
  977. .subvendor = PCI_ANY_ID,
  978. .subdevice = PCI_ANY_ID,
  979. },
  980. {
  981. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  982. .device = BFA_PCI_DEVICE_ID_CT,
  983. .subvendor = PCI_ANY_ID,
  984. .subdevice = PCI_ANY_ID,
  985. .class = (PCI_CLASS_SERIAL_FIBER << 8),
  986. .class_mask = ~0,
  987. },
  988. {0, 0},
  989. };
  990. MODULE_DEVICE_TABLE(pci, bfad_id_table);
  991. static struct pci_driver bfad_pci_driver = {
  992. .name = BFAD_DRIVER_NAME,
  993. .id_table = bfad_id_table,
  994. .probe = bfad_pci_probe,
  995. .remove = __devexit_p(bfad_pci_remove),
  996. };
  997. /**
  998. * Linux driver module functions
  999. */
  1000. bfa_status_t
  1001. bfad_fc4_module_init(void)
  1002. {
  1003. int rc;
  1004. rc = bfad_im_module_init();
  1005. if (rc != BFA_STATUS_OK)
  1006. goto ext;
  1007. bfad_tm_module_init();
  1008. if (ipfc_enable)
  1009. bfad_ipfc_module_init();
  1010. ext:
  1011. return rc;
  1012. }
  1013. void
  1014. bfad_fc4_module_exit(void)
  1015. {
  1016. if (ipfc_enable)
  1017. bfad_ipfc_module_exit();
  1018. bfad_tm_module_exit();
  1019. bfad_im_module_exit();
  1020. }
  1021. /**
  1022. * Driver module init.
  1023. */
  1024. static int __init
  1025. bfad_init(void)
  1026. {
  1027. int error = 0;
  1028. printk(KERN_INFO "Brocade BFA FC/FCOE SCSI driver - version: %s\n",
  1029. BFAD_DRIVER_VERSION);
  1030. if (num_sgpgs > 0)
  1031. num_sgpgs_parm = num_sgpgs;
  1032. error = bfad_fc4_module_init();
  1033. if (error) {
  1034. error = -ENOMEM;
  1035. printk(KERN_WARNING "bfad_fc4_module_init failure\n");
  1036. goto ext;
  1037. }
  1038. if (!strcmp(FCPI_NAME, " fcpim"))
  1039. bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_IM;
  1040. if (!strcmp(FCPT_NAME, " fcptm"))
  1041. bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_TM;
  1042. if (!strcmp(IPFC_NAME, " ipfc"))
  1043. bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_IPFC;
  1044. bfa_ioc_auto_recover(ioc_auto_recover);
  1045. bfa_fcs_rport_set_del_timeout(rport_del_timeout);
  1046. error = pci_register_driver(&bfad_pci_driver);
  1047. if (error) {
  1048. printk(KERN_WARNING "bfad pci_register_driver failure\n");
  1049. goto ext;
  1050. }
  1051. return 0;
  1052. ext:
  1053. bfad_fc4_module_exit();
  1054. return error;
  1055. }
  1056. /**
  1057. * Driver module exit.
  1058. */
  1059. static void __exit
  1060. bfad_exit(void)
  1061. {
  1062. pci_unregister_driver(&bfad_pci_driver);
  1063. bfad_fc4_module_exit();
  1064. bfad_free_fwimg();
  1065. }
  1066. #define BFAD_PROTO_NAME FCPI_NAME FCPT_NAME IPFC_NAME
  1067. module_init(bfad_init);
  1068. module_exit(bfad_exit);
  1069. MODULE_LICENSE("GPL");
  1070. MODULE_DESCRIPTION("Brocade Fibre Channel HBA Driver" BFAD_PROTO_NAME);
  1071. MODULE_AUTHOR("Brocade Communications Systems, Inc.");
  1072. MODULE_VERSION(BFAD_DRIVER_VERSION);