bfad.c 30 KB

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