bfad.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  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. static 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. kfree(vport_drv);
  257. }
  258. /**
  259. * FCS RPORT alloc callback, after successful PLOGI by FCS
  260. */
  261. bfa_status_t
  262. bfa_fcb_rport_alloc(struct bfad_s *bfad, struct bfa_fcs_rport_s **rport,
  263. struct bfad_rport_s **rport_drv)
  264. {
  265. bfa_status_t rc = BFA_STATUS_OK;
  266. *rport_drv = kzalloc(sizeof(struct bfad_rport_s), GFP_ATOMIC);
  267. if (*rport_drv == NULL) {
  268. rc = BFA_STATUS_ENOMEM;
  269. goto ext;
  270. }
  271. *rport = &(*rport_drv)->fcs_rport;
  272. ext:
  273. return rc;
  274. }
  275. void
  276. bfad_hal_mem_release(struct bfad_s *bfad)
  277. {
  278. int i;
  279. struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
  280. struct bfa_mem_elem_s *meminfo_elem;
  281. for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
  282. meminfo_elem = &hal_meminfo->meminfo[i];
  283. if (meminfo_elem->kva != NULL) {
  284. switch (meminfo_elem->mem_type) {
  285. case BFA_MEM_TYPE_KVA:
  286. vfree(meminfo_elem->kva);
  287. break;
  288. case BFA_MEM_TYPE_DMA:
  289. dma_free_coherent(&bfad->pcidev->dev,
  290. meminfo_elem->mem_len,
  291. meminfo_elem->kva,
  292. (dma_addr_t) meminfo_elem->dma);
  293. break;
  294. default:
  295. bfa_assert(0);
  296. break;
  297. }
  298. }
  299. }
  300. memset(hal_meminfo, 0, sizeof(struct bfa_meminfo_s));
  301. }
  302. void
  303. bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg)
  304. {
  305. if (num_rports > 0)
  306. bfa_cfg->fwcfg.num_rports = num_rports;
  307. if (num_ios > 0)
  308. bfa_cfg->fwcfg.num_ioim_reqs = num_ios;
  309. if (num_tms > 0)
  310. bfa_cfg->fwcfg.num_tskim_reqs = num_tms;
  311. if (num_fcxps > 0)
  312. bfa_cfg->fwcfg.num_fcxp_reqs = num_fcxps;
  313. if (num_ufbufs > 0)
  314. bfa_cfg->fwcfg.num_uf_bufs = num_ufbufs;
  315. if (reqq_size > 0)
  316. bfa_cfg->drvcfg.num_reqq_elems = reqq_size;
  317. if (rspq_size > 0)
  318. bfa_cfg->drvcfg.num_rspq_elems = rspq_size;
  319. if (num_sgpgs > 0)
  320. bfa_cfg->drvcfg.num_sgpgs = num_sgpgs;
  321. /*
  322. * populate the hal values back to the driver for sysfs use.
  323. * otherwise, the default values will be shown as 0 in sysfs
  324. */
  325. num_rports = bfa_cfg->fwcfg.num_rports;
  326. num_ios = bfa_cfg->fwcfg.num_ioim_reqs;
  327. num_tms = bfa_cfg->fwcfg.num_tskim_reqs;
  328. num_fcxps = bfa_cfg->fwcfg.num_fcxp_reqs;
  329. num_ufbufs = bfa_cfg->fwcfg.num_uf_bufs;
  330. reqq_size = bfa_cfg->drvcfg.num_reqq_elems;
  331. rspq_size = bfa_cfg->drvcfg.num_rspq_elems;
  332. num_sgpgs = bfa_cfg->drvcfg.num_sgpgs;
  333. }
  334. bfa_status_t
  335. bfad_hal_mem_alloc(struct bfad_s *bfad)
  336. {
  337. struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
  338. struct bfa_mem_elem_s *meminfo_elem;
  339. bfa_status_t rc = BFA_STATUS_OK;
  340. dma_addr_t phys_addr;
  341. int retry_count = 0;
  342. int reset_value = 1;
  343. int min_num_sgpgs = 512;
  344. void *kva;
  345. int i;
  346. bfa_cfg_get_default(&bfad->ioc_cfg);
  347. retry:
  348. bfad_update_hal_cfg(&bfad->ioc_cfg);
  349. bfad->cfg_data.ioc_queue_depth = bfad->ioc_cfg.fwcfg.num_ioim_reqs;
  350. bfa_cfg_get_meminfo(&bfad->ioc_cfg, hal_meminfo);
  351. for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
  352. meminfo_elem = &hal_meminfo->meminfo[i];
  353. switch (meminfo_elem->mem_type) {
  354. case BFA_MEM_TYPE_KVA:
  355. kva = vmalloc(meminfo_elem->mem_len);
  356. if (kva == NULL) {
  357. bfad_hal_mem_release(bfad);
  358. rc = BFA_STATUS_ENOMEM;
  359. goto ext;
  360. }
  361. memset(kva, 0, meminfo_elem->mem_len);
  362. meminfo_elem->kva = kva;
  363. break;
  364. case BFA_MEM_TYPE_DMA:
  365. kva = dma_alloc_coherent(&bfad->pcidev->dev,
  366. meminfo_elem->mem_len,
  367. &phys_addr, GFP_KERNEL);
  368. if (kva == NULL) {
  369. bfad_hal_mem_release(bfad);
  370. /*
  371. * If we cannot allocate with default
  372. * num_sgpages try with half the value.
  373. */
  374. if (num_sgpgs > min_num_sgpgs) {
  375. printk(KERN_INFO "bfad[%d]: memory"
  376. " allocation failed with"
  377. " num_sgpgs: %d\n",
  378. bfad->inst_no, num_sgpgs);
  379. nextLowerInt(&num_sgpgs);
  380. printk(KERN_INFO "bfad[%d]: trying to"
  381. " allocate memory with"
  382. " num_sgpgs: %d\n",
  383. bfad->inst_no, num_sgpgs);
  384. retry_count++;
  385. goto retry;
  386. } else {
  387. if (num_sgpgs_parm > 0)
  388. num_sgpgs = num_sgpgs_parm;
  389. else {
  390. reset_value =
  391. (1 << retry_count);
  392. num_sgpgs *= reset_value;
  393. }
  394. rc = BFA_STATUS_ENOMEM;
  395. goto ext;
  396. }
  397. }
  398. if (num_sgpgs_parm > 0)
  399. num_sgpgs = num_sgpgs_parm;
  400. else {
  401. reset_value = (1 << retry_count);
  402. num_sgpgs *= reset_value;
  403. }
  404. memset(kva, 0, meminfo_elem->mem_len);
  405. meminfo_elem->kva = kva;
  406. meminfo_elem->dma = phys_addr;
  407. break;
  408. default:
  409. break;
  410. }
  411. }
  412. ext:
  413. return rc;
  414. }
  415. /**
  416. * Create a vport under a vf.
  417. */
  418. bfa_status_t
  419. bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
  420. struct bfa_port_cfg_s *port_cfg)
  421. {
  422. struct bfad_vport_s *vport;
  423. int rc = BFA_STATUS_OK;
  424. unsigned long flags;
  425. struct completion fcomp;
  426. vport = kzalloc(sizeof(struct bfad_vport_s), GFP_KERNEL);
  427. if (!vport) {
  428. rc = BFA_STATUS_ENOMEM;
  429. goto ext;
  430. }
  431. vport->drv_port.bfad = bfad;
  432. spin_lock_irqsave(&bfad->bfad_lock, flags);
  433. rc = bfa_fcs_vport_create(&vport->fcs_vport, &bfad->bfa_fcs, vf_id,
  434. port_cfg, vport);
  435. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  436. if (rc != BFA_STATUS_OK)
  437. goto ext_free_vport;
  438. if (port_cfg->roles & BFA_PORT_ROLE_FCP_IM) {
  439. rc = bfad_im_scsi_host_alloc(bfad, vport->drv_port.im_port);
  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. unsigned long bar0_len;
  510. int rc = -ENODEV;
  511. if (pci_enable_device(pdev)) {
  512. BFA_PRINTF(BFA_ERR, "pci_enable_device fail %p\n", pdev);
  513. goto out;
  514. }
  515. if (pci_request_regions(pdev, BFAD_DRIVER_NAME))
  516. goto out_disable_device;
  517. pci_set_master(pdev);
  518. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
  519. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
  520. BFA_PRINTF(BFA_ERR, "pci_set_dma_mask fail %p\n", pdev);
  521. goto out_release_region;
  522. }
  523. bfad->pci_bar0_map = pci_resource_start(pdev, 0);
  524. bar0_len = pci_resource_len(pdev, 0);
  525. bfad->pci_bar0_kva = ioremap(bfad->pci_bar0_map, bar0_len);
  526. if (bfad->pci_bar0_kva == NULL) {
  527. BFA_PRINTF(BFA_ERR, "Fail to map bar0\n");
  528. goto out_release_region;
  529. }
  530. bfad->hal_pcidev.pci_slot = PCI_SLOT(pdev->devfn);
  531. bfad->hal_pcidev.pci_func = PCI_FUNC(pdev->devfn);
  532. bfad->hal_pcidev.pci_bar_kva = bfad->pci_bar0_kva;
  533. bfad->hal_pcidev.device_id = pdev->device;
  534. bfad->pci_name = pci_name(pdev);
  535. bfad->pci_attr.vendor_id = pdev->vendor;
  536. bfad->pci_attr.device_id = pdev->device;
  537. bfad->pci_attr.ssid = pdev->subsystem_device;
  538. bfad->pci_attr.ssvid = pdev->subsystem_vendor;
  539. bfad->pci_attr.pcifn = PCI_FUNC(pdev->devfn);
  540. bfad->pcidev = pdev;
  541. return 0;
  542. out_release_region:
  543. pci_release_regions(pdev);
  544. out_disable_device:
  545. pci_disable_device(pdev);
  546. out:
  547. return rc;
  548. }
  549. void
  550. bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad)
  551. {
  552. #if defined(__ia64__)
  553. pci_iounmap(pdev, bfad->pci_bar0_kva);
  554. #else
  555. iounmap(bfad->pci_bar0_kva);
  556. #endif
  557. pci_release_regions(pdev);
  558. pci_disable_device(pdev);
  559. pci_set_drvdata(pdev, NULL);
  560. }
  561. void
  562. bfad_fcs_port_cfg(struct bfad_s *bfad)
  563. {
  564. struct bfa_port_cfg_s port_cfg;
  565. struct bfa_pport_attr_s attr;
  566. char symname[BFA_SYMNAME_MAXLEN];
  567. sprintf(symname, "%s-%d", BFAD_DRIVER_NAME, bfad->inst_no);
  568. memcpy(port_cfg.sym_name.symname, symname, strlen(symname));
  569. bfa_fcport_get_attr(&bfad->bfa, &attr);
  570. port_cfg.nwwn = attr.nwwn;
  571. port_cfg.pwwn = attr.pwwn;
  572. bfa_fcs_cfg_base_port(&bfad->bfa_fcs, &port_cfg);
  573. }
  574. bfa_status_t
  575. bfad_drv_init(struct bfad_s *bfad)
  576. {
  577. bfa_status_t rc;
  578. unsigned long flags;
  579. struct bfa_fcs_driver_info_s driver_info;
  580. bfad->cfg_data.rport_del_timeout = rport_del_timeout;
  581. bfad->cfg_data.lun_queue_depth = bfa_lun_queue_depth;
  582. bfad->cfg_data.io_max_sge = bfa_io_max_sge;
  583. bfad->cfg_data.binding_method = FCP_PWWN_BINDING;
  584. rc = bfad_hal_mem_alloc(bfad);
  585. if (rc != BFA_STATUS_OK) {
  586. printk(KERN_WARNING "bfad%d bfad_hal_mem_alloc failure\n",
  587. bfad->inst_no);
  588. printk(KERN_WARNING
  589. "Not enough memory to attach all Brocade HBA ports,"
  590. " System may need more memory.\n");
  591. goto out_hal_mem_alloc_failure;
  592. }
  593. bfa_init_log(&bfad->bfa, bfad->logmod);
  594. bfa_init_trc(&bfad->bfa, bfad->trcmod);
  595. bfa_init_aen(&bfad->bfa, bfad->aen);
  596. memset(bfad->file_map, 0, sizeof(bfad->file_map));
  597. bfa_init_plog(&bfad->bfa, &bfad->plog_buf);
  598. bfa_plog_init(&bfad->plog_buf);
  599. bfa_plog_str(&bfad->plog_buf, BFA_PL_MID_DRVR, BFA_PL_EID_DRIVER_START,
  600. 0, "Driver Attach");
  601. bfa_attach(&bfad->bfa, bfad, &bfad->ioc_cfg, &bfad->meminfo,
  602. &bfad->hal_pcidev);
  603. init_completion(&bfad->comp);
  604. /*
  605. * Enable Interrupt and wait bfa_init completion
  606. */
  607. if (bfad_setup_intr(bfad)) {
  608. printk(KERN_WARNING "bfad%d: bfad_setup_intr failed\n",
  609. bfad->inst_no);
  610. goto out_setup_intr_failure;
  611. }
  612. spin_lock_irqsave(&bfad->bfad_lock, flags);
  613. bfa_init(&bfad->bfa);
  614. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  615. /*
  616. * Set up interrupt handler for each vectors
  617. */
  618. if ((bfad->bfad_flags & BFAD_MSIX_ON)
  619. && bfad_install_msix_handler(bfad)) {
  620. printk(KERN_WARNING "%s: install_msix failed, bfad%d\n",
  621. __func__, bfad->inst_no);
  622. }
  623. bfad_init_timer(bfad);
  624. wait_for_completion(&bfad->comp);
  625. memset(&driver_info, 0, sizeof(driver_info));
  626. strncpy(driver_info.version, BFAD_DRIVER_VERSION,
  627. sizeof(driver_info.version) - 1);
  628. if (host_name)
  629. strncpy(driver_info.host_machine_name, host_name,
  630. sizeof(driver_info.host_machine_name) - 1);
  631. if (os_name)
  632. strncpy(driver_info.host_os_name, os_name,
  633. sizeof(driver_info.host_os_name) - 1);
  634. if (os_patch)
  635. strncpy(driver_info.host_os_patch, os_patch,
  636. sizeof(driver_info.host_os_patch) - 1);
  637. strncpy(driver_info.os_device_name, bfad->pci_name,
  638. sizeof(driver_info.os_device_name - 1));
  639. /*
  640. * FCS INIT
  641. */
  642. spin_lock_irqsave(&bfad->bfad_lock, flags);
  643. bfa_fcs_log_init(&bfad->bfa_fcs, bfad->logmod);
  644. bfa_fcs_trc_init(&bfad->bfa_fcs, bfad->trcmod);
  645. bfa_fcs_aen_init(&bfad->bfa_fcs, bfad->aen);
  646. bfa_fcs_attach(&bfad->bfa_fcs, &bfad->bfa, bfad, BFA_FALSE);
  647. /* Do FCS init only when HAL init is done */
  648. if ((bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
  649. bfa_fcs_init(&bfad->bfa_fcs);
  650. bfad->bfad_flags |= BFAD_FCS_INIT_DONE;
  651. }
  652. bfa_fcs_driver_info_init(&bfad->bfa_fcs, &driver_info);
  653. bfa_fcs_set_fdmi_param(&bfad->bfa_fcs, fdmi_enable);
  654. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  655. bfad->bfad_flags |= BFAD_DRV_INIT_DONE;
  656. return BFA_STATUS_OK;
  657. out_setup_intr_failure:
  658. bfa_detach(&bfad->bfa);
  659. bfad_hal_mem_release(bfad);
  660. out_hal_mem_alloc_failure:
  661. return BFA_STATUS_FAILED;
  662. }
  663. void
  664. bfad_drv_uninit(struct bfad_s *bfad)
  665. {
  666. unsigned long flags;
  667. spin_lock_irqsave(&bfad->bfad_lock, flags);
  668. init_completion(&bfad->comp);
  669. bfa_stop(&bfad->bfa);
  670. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  671. wait_for_completion(&bfad->comp);
  672. del_timer_sync(&bfad->hal_tmo);
  673. bfa_isr_disable(&bfad->bfa);
  674. bfa_detach(&bfad->bfa);
  675. bfad_remove_intr(bfad);
  676. bfad_hal_mem_release(bfad);
  677. bfad->bfad_flags &= ~BFAD_DRV_INIT_DONE;
  678. }
  679. void
  680. bfad_drv_start(struct bfad_s *bfad)
  681. {
  682. unsigned long flags;
  683. spin_lock_irqsave(&bfad->bfad_lock, flags);
  684. bfa_start(&bfad->bfa);
  685. bfa_fcs_start(&bfad->bfa_fcs);
  686. bfad->bfad_flags |= BFAD_HAL_START_DONE;
  687. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  688. bfad_fc4_probe_post(bfad);
  689. }
  690. void
  691. bfad_drv_stop(struct bfad_s *bfad)
  692. {
  693. unsigned long flags;
  694. spin_lock_irqsave(&bfad->bfad_lock, flags);
  695. init_completion(&bfad->comp);
  696. bfad->pport.flags |= BFAD_PORT_DELETE;
  697. bfa_fcs_exit(&bfad->bfa_fcs);
  698. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  699. wait_for_completion(&bfad->comp);
  700. spin_lock_irqsave(&bfad->bfad_lock, flags);
  701. init_completion(&bfad->comp);
  702. bfa_stop(&bfad->bfa);
  703. bfad->bfad_flags &= ~BFAD_HAL_START_DONE;
  704. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  705. wait_for_completion(&bfad->comp);
  706. }
  707. bfa_status_t
  708. bfad_cfg_pport(struct bfad_s *bfad, enum bfa_port_role role)
  709. {
  710. int rc = BFA_STATUS_OK;
  711. /*
  712. * Allocate scsi_host for the physical port
  713. */
  714. if ((bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IM)
  715. && (role & BFA_PORT_ROLE_FCP_IM)) {
  716. if (bfad->pport.im_port == NULL) {
  717. rc = BFA_STATUS_FAILED;
  718. goto out;
  719. }
  720. rc = bfad_im_scsi_host_alloc(bfad, bfad->pport.im_port);
  721. if (rc != BFA_STATUS_OK)
  722. goto out;
  723. bfad->pport.roles |= BFA_PORT_ROLE_FCP_IM;
  724. }
  725. bfad->bfad_flags |= BFAD_CFG_PPORT_DONE;
  726. out:
  727. return rc;
  728. }
  729. void
  730. bfad_uncfg_pport(struct bfad_s *bfad)
  731. {
  732. if ((bfad->pport.roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable) {
  733. bfad_ipfc_port_delete(bfad, &bfad->pport);
  734. bfad->pport.roles &= ~BFA_PORT_ROLE_FCP_IPFC;
  735. }
  736. if ((bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IM)
  737. && (bfad->pport.roles & BFA_PORT_ROLE_FCP_IM)) {
  738. bfad_im_scsi_host_free(bfad, bfad->pport.im_port);
  739. bfad_im_port_clean(bfad->pport.im_port);
  740. kfree(bfad->pport.im_port);
  741. bfad->pport.roles &= ~BFA_PORT_ROLE_FCP_IM;
  742. }
  743. bfad->bfad_flags &= ~BFAD_CFG_PPORT_DONE;
  744. }
  745. void
  746. bfad_drv_log_level_set(struct bfad_s *bfad)
  747. {
  748. if (log_level > BFA_LOG_INVALID && log_level <= BFA_LOG_LEVEL_MAX)
  749. bfa_log_set_level_all(&bfad->log_data, log_level);
  750. }
  751. bfa_status_t
  752. bfad_start_ops(struct bfad_s *bfad)
  753. {
  754. int retval;
  755. /* PPORT FCS config */
  756. bfad_fcs_port_cfg(bfad);
  757. retval = bfad_cfg_pport(bfad, BFA_PORT_ROLE_FCP_IM);
  758. if (retval != BFA_STATUS_OK)
  759. goto out_cfg_pport_failure;
  760. /* BFAD level FC4 (IM/TM/IPFC) specific resource allocation */
  761. retval = bfad_fc4_probe(bfad);
  762. if (retval != BFA_STATUS_OK) {
  763. printk(KERN_WARNING "bfad_fc4_probe failed\n");
  764. goto out_fc4_probe_failure;
  765. }
  766. bfad_drv_start(bfad);
  767. /*
  768. * If bfa_linkup_delay is set to -1 default; try to retrive the
  769. * value using the bfad_os_get_linkup_delay(); else use the
  770. * passed in module param value as the bfa_linkup_delay.
  771. */
  772. if (bfa_linkup_delay < 0) {
  773. bfa_linkup_delay = bfad_os_get_linkup_delay(bfad);
  774. bfad_os_rport_online_wait(bfad);
  775. bfa_linkup_delay = -1;
  776. } else {
  777. bfad_os_rport_online_wait(bfad);
  778. }
  779. bfa_log(bfad->logmod, BFA_LOG_LINUX_DEVICE_CLAIMED, bfad->pci_name);
  780. return BFA_STATUS_OK;
  781. out_fc4_probe_failure:
  782. bfad_fc4_probe_undo(bfad);
  783. bfad_uncfg_pport(bfad);
  784. out_cfg_pport_failure:
  785. return BFA_STATUS_FAILED;
  786. }
  787. int
  788. bfad_worker (void *ptr)
  789. {
  790. struct bfad_s *bfad;
  791. unsigned long flags;
  792. bfad = (struct bfad_s *)ptr;
  793. while (!kthread_should_stop()) {
  794. /* Check if the FCS init is done from bfad_drv_init;
  795. * if not done do FCS init and set the flag.
  796. */
  797. if (!(bfad->bfad_flags & BFAD_FCS_INIT_DONE)) {
  798. spin_lock_irqsave(&bfad->bfad_lock, flags);
  799. bfa_fcs_init(&bfad->bfa_fcs);
  800. bfad->bfad_flags |= BFAD_FCS_INIT_DONE;
  801. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  802. }
  803. /* Start the bfad operations after HAL init done */
  804. bfad_start_ops(bfad);
  805. spin_lock_irqsave(&bfad->bfad_lock, flags);
  806. bfad->bfad_tsk = NULL;
  807. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  808. break;
  809. }
  810. return 0;
  811. }
  812. /*
  813. * PCI_entry PCI driver entries * {
  814. */
  815. /**
  816. * PCI probe entry.
  817. */
  818. int
  819. bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
  820. {
  821. struct bfad_s *bfad;
  822. int error = -ENODEV, retval;
  823. /*
  824. * For single port cards - only claim function 0
  825. */
  826. if ((pdev->device == BFA_PCI_DEVICE_ID_FC_8G1P)
  827. && (PCI_FUNC(pdev->devfn) != 0))
  828. return -ENODEV;
  829. BFA_TRACE(BFA_INFO, "bfad_pci_probe entry");
  830. bfad = kzalloc(sizeof(struct bfad_s), GFP_KERNEL);
  831. if (!bfad) {
  832. error = -ENOMEM;
  833. goto out;
  834. }
  835. bfad->trcmod = kzalloc(sizeof(struct bfa_trc_mod_s), GFP_KERNEL);
  836. if (!bfad->trcmod) {
  837. printk(KERN_WARNING "Error alloc trace buffer!\n");
  838. error = -ENOMEM;
  839. goto out_alloc_trace_failure;
  840. }
  841. /*
  842. * LOG/TRACE INIT
  843. */
  844. bfa_trc_init(bfad->trcmod);
  845. bfa_trc(bfad, bfad_inst);
  846. bfad->logmod = &bfad->log_data;
  847. bfa_log_init(bfad->logmod, (char *)pci_name(pdev), bfa_os_printf);
  848. bfad_drv_log_level_set(bfad);
  849. bfad->aen = &bfad->aen_buf;
  850. if (!(bfad_load_fwimg(pdev))) {
  851. printk(KERN_WARNING "bfad_load_fwimg failure!\n");
  852. kfree(bfad->trcmod);
  853. goto out_alloc_trace_failure;
  854. }
  855. retval = bfad_pci_init(pdev, bfad);
  856. if (retval) {
  857. printk(KERN_WARNING "bfad_pci_init failure!\n");
  858. error = retval;
  859. goto out_pci_init_failure;
  860. }
  861. mutex_lock(&bfad_mutex);
  862. bfad->inst_no = bfad_inst++;
  863. list_add_tail(&bfad->list_entry, &bfad_list);
  864. mutex_unlock(&bfad_mutex);
  865. spin_lock_init(&bfad->bfad_lock);
  866. pci_set_drvdata(pdev, bfad);
  867. bfad->ref_count = 0;
  868. bfad->pport.bfad = bfad;
  869. bfad->bfad_tsk = kthread_create(bfad_worker, (void *) bfad, "%s",
  870. "bfad_worker");
  871. if (IS_ERR(bfad->bfad_tsk)) {
  872. printk(KERN_INFO "bfad[%d]: Kernel thread"
  873. " creation failed!\n",
  874. bfad->inst_no);
  875. goto out_kthread_create_failure;
  876. }
  877. retval = bfad_drv_init(bfad);
  878. if (retval != BFA_STATUS_OK)
  879. goto out_drv_init_failure;
  880. if (!(bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
  881. bfad->bfad_flags |= BFAD_HAL_INIT_FAIL;
  882. printk(KERN_WARNING "bfad%d: hal init failed\n", bfad->inst_no);
  883. goto ok;
  884. }
  885. retval = bfad_start_ops(bfad);
  886. if (retval != BFA_STATUS_OK)
  887. goto out_start_ops_failure;
  888. kthread_stop(bfad->bfad_tsk);
  889. bfad->bfad_tsk = NULL;
  890. ok:
  891. return 0;
  892. out_start_ops_failure:
  893. bfad_drv_uninit(bfad);
  894. out_drv_init_failure:
  895. kthread_stop(bfad->bfad_tsk);
  896. out_kthread_create_failure:
  897. mutex_lock(&bfad_mutex);
  898. bfad_inst--;
  899. list_del(&bfad->list_entry);
  900. mutex_unlock(&bfad_mutex);
  901. bfad_pci_uninit(pdev, bfad);
  902. out_pci_init_failure:
  903. kfree(bfad->trcmod);
  904. out_alloc_trace_failure:
  905. kfree(bfad);
  906. out:
  907. return error;
  908. }
  909. /**
  910. * PCI remove entry.
  911. */
  912. void
  913. bfad_pci_remove(struct pci_dev *pdev)
  914. {
  915. struct bfad_s *bfad = pci_get_drvdata(pdev);
  916. unsigned long flags;
  917. bfa_trc(bfad, bfad->inst_no);
  918. spin_lock_irqsave(&bfad->bfad_lock, flags);
  919. if (bfad->bfad_tsk != NULL)
  920. kthread_stop(bfad->bfad_tsk);
  921. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  922. if ((bfad->bfad_flags & BFAD_DRV_INIT_DONE)
  923. && !(bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
  924. spin_lock_irqsave(&bfad->bfad_lock, flags);
  925. init_completion(&bfad->comp);
  926. bfa_stop(&bfad->bfa);
  927. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  928. wait_for_completion(&bfad->comp);
  929. bfad_remove_intr(bfad);
  930. del_timer_sync(&bfad->hal_tmo);
  931. goto hal_detach;
  932. } else if (!(bfad->bfad_flags & BFAD_DRV_INIT_DONE)) {
  933. goto remove_sysfs;
  934. }
  935. if (bfad->bfad_flags & BFAD_HAL_START_DONE) {
  936. bfad_drv_stop(bfad);
  937. } else if (bfad->bfad_flags & BFAD_DRV_INIT_DONE) {
  938. /* Invoking bfa_stop() before bfa_detach
  939. * when HAL and DRV init are success
  940. * but HAL start did not occur.
  941. */
  942. spin_lock_irqsave(&bfad->bfad_lock, flags);
  943. init_completion(&bfad->comp);
  944. bfa_stop(&bfad->bfa);
  945. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  946. wait_for_completion(&bfad->comp);
  947. }
  948. bfad_remove_intr(bfad);
  949. del_timer_sync(&bfad->hal_tmo);
  950. if (bfad->bfad_flags & BFAD_FC4_PROBE_DONE)
  951. bfad_fc4_probe_undo(bfad);
  952. if (bfad->bfad_flags & BFAD_CFG_PPORT_DONE)
  953. bfad_uncfg_pport(bfad);
  954. hal_detach:
  955. spin_lock_irqsave(&bfad->bfad_lock, flags);
  956. bfa_detach(&bfad->bfa);
  957. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  958. bfad_hal_mem_release(bfad);
  959. remove_sysfs:
  960. mutex_lock(&bfad_mutex);
  961. bfad_inst--;
  962. list_del(&bfad->list_entry);
  963. mutex_unlock(&bfad_mutex);
  964. bfad_pci_uninit(pdev, bfad);
  965. kfree(bfad->trcmod);
  966. kfree(bfad);
  967. }
  968. static struct pci_device_id bfad_id_table[] = {
  969. {
  970. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  971. .device = BFA_PCI_DEVICE_ID_FC_8G2P,
  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_FC_8G1P,
  978. .subvendor = PCI_ANY_ID,
  979. .subdevice = PCI_ANY_ID,
  980. },
  981. {
  982. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  983. .device = BFA_PCI_DEVICE_ID_CT,
  984. .subvendor = PCI_ANY_ID,
  985. .subdevice = PCI_ANY_ID,
  986. .class = (PCI_CLASS_SERIAL_FIBER << 8),
  987. .class_mask = ~0,
  988. },
  989. {0, 0},
  990. };
  991. MODULE_DEVICE_TABLE(pci, bfad_id_table);
  992. static struct pci_driver bfad_pci_driver = {
  993. .name = BFAD_DRIVER_NAME,
  994. .id_table = bfad_id_table,
  995. .probe = bfad_pci_probe,
  996. .remove = __devexit_p(bfad_pci_remove),
  997. };
  998. /**
  999. * Linux driver module functions
  1000. */
  1001. bfa_status_t
  1002. bfad_fc4_module_init(void)
  1003. {
  1004. int rc;
  1005. rc = bfad_im_module_init();
  1006. if (rc != BFA_STATUS_OK)
  1007. goto ext;
  1008. bfad_tm_module_init();
  1009. if (ipfc_enable)
  1010. bfad_ipfc_module_init();
  1011. ext:
  1012. return rc;
  1013. }
  1014. void
  1015. bfad_fc4_module_exit(void)
  1016. {
  1017. if (ipfc_enable)
  1018. bfad_ipfc_module_exit();
  1019. bfad_tm_module_exit();
  1020. bfad_im_module_exit();
  1021. }
  1022. /**
  1023. * Driver module init.
  1024. */
  1025. static int __init
  1026. bfad_init(void)
  1027. {
  1028. int error = 0;
  1029. printk(KERN_INFO "Brocade BFA FC/FCOE SCSI driver - version: %s\n",
  1030. BFAD_DRIVER_VERSION);
  1031. if (num_sgpgs > 0)
  1032. num_sgpgs_parm = num_sgpgs;
  1033. error = bfad_fc4_module_init();
  1034. if (error) {
  1035. error = -ENOMEM;
  1036. printk(KERN_WARNING "bfad_fc4_module_init failure\n");
  1037. goto ext;
  1038. }
  1039. if (!strcmp(FCPI_NAME, " fcpim"))
  1040. bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_IM;
  1041. if (!strcmp(FCPT_NAME, " fcptm"))
  1042. bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_TM;
  1043. if (!strcmp(IPFC_NAME, " ipfc"))
  1044. bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_IPFC;
  1045. bfa_ioc_auto_recover(ioc_auto_recover);
  1046. bfa_fcs_rport_set_del_timeout(rport_del_timeout);
  1047. error = pci_register_driver(&bfad_pci_driver);
  1048. if (error) {
  1049. printk(KERN_WARNING "bfad pci_register_driver failure\n");
  1050. goto ext;
  1051. }
  1052. return 0;
  1053. ext:
  1054. bfad_fc4_module_exit();
  1055. return error;
  1056. }
  1057. /**
  1058. * Driver module exit.
  1059. */
  1060. static void __exit
  1061. bfad_exit(void)
  1062. {
  1063. pci_unregister_driver(&bfad_pci_driver);
  1064. bfad_fc4_module_exit();
  1065. bfad_free_fwimg();
  1066. }
  1067. #define BFAD_PROTO_NAME FCPI_NAME FCPT_NAME IPFC_NAME
  1068. module_init(bfad_init);
  1069. module_exit(bfad_exit);
  1070. MODULE_LICENSE("GPL");
  1071. MODULE_DESCRIPTION("Brocade Fibre Channel HBA Driver" BFAD_PROTO_NAME);
  1072. MODULE_AUTHOR("Brocade Communications Systems, Inc.");
  1073. MODULE_VERSION(BFAD_DRIVER_VERSION);