bfad_attr.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. /*
  2. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  3. * Copyright (c) 2014- QLogic Corporation.
  4. * All rights reserved
  5. * www.qlogic.com
  6. *
  7. * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License (GPL) Version 2 as
  11. * published by the Free Software Foundation
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. */
  18. /*
  19. * bfa_attr.c Linux driver configuration interface module.
  20. */
  21. #include "bfad_drv.h"
  22. #include "bfad_im.h"
  23. /*
  24. * FC transport template entry, get SCSI target port ID.
  25. */
  26. static void
  27. bfad_im_get_starget_port_id(struct scsi_target *starget)
  28. {
  29. struct Scsi_Host *shost;
  30. struct bfad_im_port_s *im_port;
  31. struct bfad_s *bfad;
  32. struct bfad_itnim_s *itnim = NULL;
  33. u32 fc_id = -1;
  34. unsigned long flags;
  35. shost = dev_to_shost(starget->dev.parent);
  36. im_port = (struct bfad_im_port_s *) shost->hostdata[0];
  37. bfad = im_port->bfad;
  38. spin_lock_irqsave(&bfad->bfad_lock, flags);
  39. itnim = bfad_get_itnim(im_port, starget->id);
  40. if (itnim)
  41. fc_id = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
  42. fc_starget_port_id(starget) = fc_id;
  43. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  44. }
  45. /*
  46. * FC transport template entry, get SCSI target nwwn.
  47. */
  48. static void
  49. bfad_im_get_starget_node_name(struct scsi_target *starget)
  50. {
  51. struct Scsi_Host *shost;
  52. struct bfad_im_port_s *im_port;
  53. struct bfad_s *bfad;
  54. struct bfad_itnim_s *itnim = NULL;
  55. u64 node_name = 0;
  56. unsigned long flags;
  57. shost = dev_to_shost(starget->dev.parent);
  58. im_port = (struct bfad_im_port_s *) shost->hostdata[0];
  59. bfad = im_port->bfad;
  60. spin_lock_irqsave(&bfad->bfad_lock, flags);
  61. itnim = bfad_get_itnim(im_port, starget->id);
  62. if (itnim)
  63. node_name = bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim);
  64. fc_starget_node_name(starget) = cpu_to_be64(node_name);
  65. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  66. }
  67. /*
  68. * FC transport template entry, get SCSI target pwwn.
  69. */
  70. static void
  71. bfad_im_get_starget_port_name(struct scsi_target *starget)
  72. {
  73. struct Scsi_Host *shost;
  74. struct bfad_im_port_s *im_port;
  75. struct bfad_s *bfad;
  76. struct bfad_itnim_s *itnim = NULL;
  77. u64 port_name = 0;
  78. unsigned long flags;
  79. shost = dev_to_shost(starget->dev.parent);
  80. im_port = (struct bfad_im_port_s *) shost->hostdata[0];
  81. bfad = im_port->bfad;
  82. spin_lock_irqsave(&bfad->bfad_lock, flags);
  83. itnim = bfad_get_itnim(im_port, starget->id);
  84. if (itnim)
  85. port_name = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
  86. fc_starget_port_name(starget) = cpu_to_be64(port_name);
  87. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  88. }
  89. /*
  90. * FC transport template entry, get SCSI host port ID.
  91. */
  92. static void
  93. bfad_im_get_host_port_id(struct Scsi_Host *shost)
  94. {
  95. struct bfad_im_port_s *im_port =
  96. (struct bfad_im_port_s *) shost->hostdata[0];
  97. struct bfad_port_s *port = im_port->port;
  98. fc_host_port_id(shost) =
  99. bfa_hton3b(bfa_fcs_lport_get_fcid(port->fcs_port));
  100. }
  101. /*
  102. * FC transport template entry, get SCSI host port type.
  103. */
  104. static void
  105. bfad_im_get_host_port_type(struct Scsi_Host *shost)
  106. {
  107. struct bfad_im_port_s *im_port =
  108. (struct bfad_im_port_s *) shost->hostdata[0];
  109. struct bfad_s *bfad = im_port->bfad;
  110. struct bfa_lport_attr_s port_attr;
  111. bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
  112. switch (port_attr.port_type) {
  113. case BFA_PORT_TYPE_NPORT:
  114. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  115. break;
  116. case BFA_PORT_TYPE_NLPORT:
  117. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  118. break;
  119. case BFA_PORT_TYPE_P2P:
  120. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  121. break;
  122. case BFA_PORT_TYPE_LPORT:
  123. fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
  124. break;
  125. default:
  126. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  127. break;
  128. }
  129. }
  130. /*
  131. * FC transport template entry, get SCSI host port state.
  132. */
  133. static void
  134. bfad_im_get_host_port_state(struct Scsi_Host *shost)
  135. {
  136. struct bfad_im_port_s *im_port =
  137. (struct bfad_im_port_s *) shost->hostdata[0];
  138. struct bfad_s *bfad = im_port->bfad;
  139. struct bfa_port_attr_s attr;
  140. bfa_fcport_get_attr(&bfad->bfa, &attr);
  141. switch (attr.port_state) {
  142. case BFA_PORT_ST_LINKDOWN:
  143. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  144. break;
  145. case BFA_PORT_ST_LINKUP:
  146. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  147. break;
  148. case BFA_PORT_ST_DISABLED:
  149. case BFA_PORT_ST_STOPPED:
  150. case BFA_PORT_ST_IOCDOWN:
  151. case BFA_PORT_ST_IOCDIS:
  152. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  153. break;
  154. case BFA_PORT_ST_UNINIT:
  155. case BFA_PORT_ST_ENABLING_QWAIT:
  156. case BFA_PORT_ST_ENABLING:
  157. case BFA_PORT_ST_DISABLING_QWAIT:
  158. case BFA_PORT_ST_DISABLING:
  159. default:
  160. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  161. break;
  162. }
  163. }
  164. /*
  165. * FC transport template entry, get SCSI host active fc4s.
  166. */
  167. static void
  168. bfad_im_get_host_active_fc4s(struct Scsi_Host *shost)
  169. {
  170. struct bfad_im_port_s *im_port =
  171. (struct bfad_im_port_s *) shost->hostdata[0];
  172. struct bfad_port_s *port = im_port->port;
  173. memset(fc_host_active_fc4s(shost), 0,
  174. sizeof(fc_host_active_fc4s(shost)));
  175. if (port->supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
  176. fc_host_active_fc4s(shost)[2] = 1;
  177. fc_host_active_fc4s(shost)[7] = 1;
  178. }
  179. /*
  180. * FC transport template entry, get SCSI host link speed.
  181. */
  182. static void
  183. bfad_im_get_host_speed(struct Scsi_Host *shost)
  184. {
  185. struct bfad_im_port_s *im_port =
  186. (struct bfad_im_port_s *) shost->hostdata[0];
  187. struct bfad_s *bfad = im_port->bfad;
  188. struct bfa_port_attr_s attr;
  189. bfa_fcport_get_attr(&bfad->bfa, &attr);
  190. switch (attr.speed) {
  191. case BFA_PORT_SPEED_10GBPS:
  192. fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
  193. break;
  194. case BFA_PORT_SPEED_16GBPS:
  195. fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
  196. break;
  197. case BFA_PORT_SPEED_8GBPS:
  198. fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
  199. break;
  200. case BFA_PORT_SPEED_4GBPS:
  201. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  202. break;
  203. case BFA_PORT_SPEED_2GBPS:
  204. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  205. break;
  206. case BFA_PORT_SPEED_1GBPS:
  207. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  208. break;
  209. default:
  210. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  211. break;
  212. }
  213. }
  214. /*
  215. * FC transport template entry, get SCSI host port type.
  216. */
  217. static void
  218. bfad_im_get_host_fabric_name(struct Scsi_Host *shost)
  219. {
  220. struct bfad_im_port_s *im_port =
  221. (struct bfad_im_port_s *) shost->hostdata[0];
  222. struct bfad_port_s *port = im_port->port;
  223. wwn_t fabric_nwwn = 0;
  224. fabric_nwwn = bfa_fcs_lport_get_fabric_name(port->fcs_port);
  225. fc_host_fabric_name(shost) = cpu_to_be64(fabric_nwwn);
  226. }
  227. /*
  228. * FC transport template entry, get BFAD statistics.
  229. */
  230. static struct fc_host_statistics *
  231. bfad_im_get_stats(struct Scsi_Host *shost)
  232. {
  233. struct bfad_im_port_s *im_port =
  234. (struct bfad_im_port_s *) shost->hostdata[0];
  235. struct bfad_s *bfad = im_port->bfad;
  236. struct bfad_hal_comp fcomp;
  237. union bfa_port_stats_u *fcstats;
  238. struct fc_host_statistics *hstats;
  239. bfa_status_t rc;
  240. unsigned long flags;
  241. fcstats = kzalloc(sizeof(union bfa_port_stats_u), GFP_KERNEL);
  242. if (fcstats == NULL)
  243. return NULL;
  244. hstats = &bfad->link_stats;
  245. init_completion(&fcomp.comp);
  246. spin_lock_irqsave(&bfad->bfad_lock, flags);
  247. memset(hstats, 0, sizeof(struct fc_host_statistics));
  248. rc = bfa_port_get_stats(BFA_FCPORT(&bfad->bfa),
  249. fcstats, bfad_hcb_comp, &fcomp);
  250. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  251. if (rc != BFA_STATUS_OK)
  252. return NULL;
  253. wait_for_completion(&fcomp.comp);
  254. /* Fill the fc_host_statistics structure */
  255. hstats->seconds_since_last_reset = fcstats->fc.secs_reset;
  256. hstats->tx_frames = fcstats->fc.tx_frames;
  257. hstats->tx_words = fcstats->fc.tx_words;
  258. hstats->rx_frames = fcstats->fc.rx_frames;
  259. hstats->rx_words = fcstats->fc.rx_words;
  260. hstats->lip_count = fcstats->fc.lip_count;
  261. hstats->nos_count = fcstats->fc.nos_count;
  262. hstats->error_frames = fcstats->fc.error_frames;
  263. hstats->dumped_frames = fcstats->fc.dropped_frames;
  264. hstats->link_failure_count = fcstats->fc.link_failures;
  265. hstats->loss_of_sync_count = fcstats->fc.loss_of_syncs;
  266. hstats->loss_of_signal_count = fcstats->fc.loss_of_signals;
  267. hstats->prim_seq_protocol_err_count = fcstats->fc.primseq_errs;
  268. hstats->invalid_crc_count = fcstats->fc.invalid_crcs;
  269. kfree(fcstats);
  270. return hstats;
  271. }
  272. /*
  273. * FC transport template entry, reset BFAD statistics.
  274. */
  275. static void
  276. bfad_im_reset_stats(struct Scsi_Host *shost)
  277. {
  278. struct bfad_im_port_s *im_port =
  279. (struct bfad_im_port_s *) shost->hostdata[0];
  280. struct bfad_s *bfad = im_port->bfad;
  281. struct bfad_hal_comp fcomp;
  282. unsigned long flags;
  283. bfa_status_t rc;
  284. init_completion(&fcomp.comp);
  285. spin_lock_irqsave(&bfad->bfad_lock, flags);
  286. rc = bfa_port_clear_stats(BFA_FCPORT(&bfad->bfa), bfad_hcb_comp,
  287. &fcomp);
  288. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  289. if (rc != BFA_STATUS_OK)
  290. return;
  291. wait_for_completion(&fcomp.comp);
  292. return;
  293. }
  294. /*
  295. * FC transport template entry, set rport loss timeout.
  296. * Update dev_loss_tmo based on the value pushed down by the stack
  297. * In case it is lesser than path_tov of driver, set it to path_tov + 1
  298. * to ensure that the driver times out before the application
  299. */
  300. static void
  301. bfad_im_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
  302. {
  303. struct bfad_itnim_data_s *itnim_data = rport->dd_data;
  304. struct bfad_itnim_s *itnim = itnim_data->itnim;
  305. struct bfad_s *bfad = itnim->im->bfad;
  306. uint16_t path_tov = bfa_fcpim_path_tov_get(&bfad->bfa);
  307. rport->dev_loss_tmo = timeout;
  308. if (timeout < path_tov)
  309. rport->dev_loss_tmo = path_tov + 1;
  310. }
  311. static int
  312. bfad_im_vport_create(struct fc_vport *fc_vport, bool disable)
  313. {
  314. char *vname = fc_vport->symbolic_name;
  315. struct Scsi_Host *shost = fc_vport->shost;
  316. struct bfad_im_port_s *im_port =
  317. (struct bfad_im_port_s *) shost->hostdata[0];
  318. struct bfad_s *bfad = im_port->bfad;
  319. struct bfa_lport_cfg_s port_cfg;
  320. struct bfad_vport_s *vp;
  321. int status = 0, rc;
  322. unsigned long flags;
  323. memset(&port_cfg, 0, sizeof(port_cfg));
  324. u64_to_wwn(fc_vport->node_name, (u8 *)&port_cfg.nwwn);
  325. u64_to_wwn(fc_vport->port_name, (u8 *)&port_cfg.pwwn);
  326. if (strlen(vname) > 0)
  327. strcpy((char *)&port_cfg.sym_name, vname);
  328. port_cfg.roles = BFA_LPORT_ROLE_FCP_IM;
  329. spin_lock_irqsave(&bfad->bfad_lock, flags);
  330. list_for_each_entry(vp, &bfad->pbc_vport_list, list_entry) {
  331. if (port_cfg.pwwn ==
  332. vp->fcs_vport.lport.port_cfg.pwwn) {
  333. port_cfg.preboot_vp =
  334. vp->fcs_vport.lport.port_cfg.preboot_vp;
  335. break;
  336. }
  337. }
  338. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  339. rc = bfad_vport_create(bfad, 0, &port_cfg, &fc_vport->dev);
  340. if (rc == BFA_STATUS_OK) {
  341. struct bfad_vport_s *vport;
  342. struct bfa_fcs_vport_s *fcs_vport;
  343. struct Scsi_Host *vshost;
  344. spin_lock_irqsave(&bfad->bfad_lock, flags);
  345. fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0,
  346. port_cfg.pwwn);
  347. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  348. if (fcs_vport == NULL)
  349. return VPCERR_BAD_WWN;
  350. fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
  351. if (disable) {
  352. spin_lock_irqsave(&bfad->bfad_lock, flags);
  353. bfa_fcs_vport_stop(fcs_vport);
  354. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  355. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  356. }
  357. vport = fcs_vport->vport_drv;
  358. vshost = vport->drv_port.im_port->shost;
  359. fc_host_node_name(vshost) = wwn_to_u64((u8 *)&port_cfg.nwwn);
  360. fc_host_port_name(vshost) = wwn_to_u64((u8 *)&port_cfg.pwwn);
  361. fc_host_supported_classes(vshost) = FC_COS_CLASS3;
  362. memset(fc_host_supported_fc4s(vshost), 0,
  363. sizeof(fc_host_supported_fc4s(vshost)));
  364. /* For FCP type 0x08 */
  365. if (supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
  366. fc_host_supported_fc4s(vshost)[2] = 1;
  367. /* For fibre channel services type 0x20 */
  368. fc_host_supported_fc4s(vshost)[7] = 1;
  369. fc_host_supported_speeds(vshost) =
  370. bfad_im_supported_speeds(&bfad->bfa);
  371. fc_host_maxframe_size(vshost) =
  372. bfa_fcport_get_maxfrsize(&bfad->bfa);
  373. fc_vport->dd_data = vport;
  374. vport->drv_port.im_port->fc_vport = fc_vport;
  375. } else if (rc == BFA_STATUS_INVALID_WWN)
  376. return VPCERR_BAD_WWN;
  377. else if (rc == BFA_STATUS_VPORT_EXISTS)
  378. return VPCERR_BAD_WWN;
  379. else if (rc == BFA_STATUS_VPORT_MAX)
  380. return VPCERR_NO_FABRIC_SUPP;
  381. else if (rc == BFA_STATUS_VPORT_WWN_BP)
  382. return VPCERR_BAD_WWN;
  383. else
  384. return FC_VPORT_FAILED;
  385. return status;
  386. }
  387. int
  388. bfad_im_issue_fc_host_lip(struct Scsi_Host *shost)
  389. {
  390. struct bfad_im_port_s *im_port =
  391. (struct bfad_im_port_s *) shost->hostdata[0];
  392. struct bfad_s *bfad = im_port->bfad;
  393. struct bfad_hal_comp fcomp;
  394. unsigned long flags;
  395. uint32_t status;
  396. init_completion(&fcomp.comp);
  397. spin_lock_irqsave(&bfad->bfad_lock, flags);
  398. status = bfa_port_disable(&bfad->bfa.modules.port,
  399. bfad_hcb_comp, &fcomp);
  400. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  401. if (status != BFA_STATUS_OK)
  402. return -EIO;
  403. wait_for_completion(&fcomp.comp);
  404. if (fcomp.status != BFA_STATUS_OK)
  405. return -EIO;
  406. spin_lock_irqsave(&bfad->bfad_lock, flags);
  407. status = bfa_port_enable(&bfad->bfa.modules.port,
  408. bfad_hcb_comp, &fcomp);
  409. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  410. if (status != BFA_STATUS_OK)
  411. return -EIO;
  412. wait_for_completion(&fcomp.comp);
  413. if (fcomp.status != BFA_STATUS_OK)
  414. return -EIO;
  415. return 0;
  416. }
  417. static int
  418. bfad_im_vport_delete(struct fc_vport *fc_vport)
  419. {
  420. struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
  421. struct bfad_im_port_s *im_port =
  422. (struct bfad_im_port_s *) vport->drv_port.im_port;
  423. struct bfad_s *bfad = im_port->bfad;
  424. struct bfad_port_s *port;
  425. struct bfa_fcs_vport_s *fcs_vport;
  426. struct Scsi_Host *vshost;
  427. wwn_t pwwn;
  428. int rc;
  429. unsigned long flags;
  430. struct completion fcomp;
  431. if (im_port->flags & BFAD_PORT_DELETE) {
  432. bfad_scsi_host_free(bfad, im_port);
  433. list_del(&vport->list_entry);
  434. kfree(vport);
  435. return 0;
  436. }
  437. port = im_port->port;
  438. vshost = vport->drv_port.im_port->shost;
  439. u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
  440. spin_lock_irqsave(&bfad->bfad_lock, flags);
  441. fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
  442. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  443. if (fcs_vport == NULL)
  444. return VPCERR_BAD_WWN;
  445. vport->drv_port.flags |= BFAD_PORT_DELETE;
  446. vport->comp_del = &fcomp;
  447. init_completion(vport->comp_del);
  448. spin_lock_irqsave(&bfad->bfad_lock, flags);
  449. rc = bfa_fcs_vport_delete(&vport->fcs_vport);
  450. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  451. if (rc == BFA_STATUS_PBC) {
  452. vport->drv_port.flags &= ~BFAD_PORT_DELETE;
  453. vport->comp_del = NULL;
  454. return -1;
  455. }
  456. wait_for_completion(vport->comp_del);
  457. bfad_scsi_host_free(bfad, im_port);
  458. list_del(&vport->list_entry);
  459. kfree(vport);
  460. return 0;
  461. }
  462. static int
  463. bfad_im_vport_disable(struct fc_vport *fc_vport, bool disable)
  464. {
  465. struct bfad_vport_s *vport;
  466. struct bfad_s *bfad;
  467. struct bfa_fcs_vport_s *fcs_vport;
  468. struct Scsi_Host *vshost;
  469. wwn_t pwwn;
  470. unsigned long flags;
  471. vport = (struct bfad_vport_s *)fc_vport->dd_data;
  472. bfad = vport->drv_port.bfad;
  473. vshost = vport->drv_port.im_port->shost;
  474. u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
  475. spin_lock_irqsave(&bfad->bfad_lock, flags);
  476. fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
  477. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  478. if (fcs_vport == NULL)
  479. return VPCERR_BAD_WWN;
  480. if (disable) {
  481. bfa_fcs_vport_stop(fcs_vport);
  482. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  483. } else {
  484. bfa_fcs_vport_start(fcs_vport);
  485. fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
  486. }
  487. return 0;
  488. }
  489. void
  490. bfad_im_vport_set_symbolic_name(struct fc_vport *fc_vport)
  491. {
  492. struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
  493. struct bfad_im_port_s *im_port =
  494. (struct bfad_im_port_s *)vport->drv_port.im_port;
  495. struct bfad_s *bfad = im_port->bfad;
  496. struct Scsi_Host *vshost = vport->drv_port.im_port->shost;
  497. char *sym_name = fc_vport->symbolic_name;
  498. struct bfa_fcs_vport_s *fcs_vport;
  499. wwn_t pwwn;
  500. unsigned long flags;
  501. u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
  502. spin_lock_irqsave(&bfad->bfad_lock, flags);
  503. fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
  504. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  505. if (fcs_vport == NULL)
  506. return;
  507. spin_lock_irqsave(&bfad->bfad_lock, flags);
  508. if (strlen(sym_name) > 0)
  509. bfa_fcs_lport_set_symname(&fcs_vport->lport, sym_name);
  510. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  511. }
  512. struct fc_function_template bfad_im_fc_function_template = {
  513. /* Target dynamic attributes */
  514. .get_starget_port_id = bfad_im_get_starget_port_id,
  515. .show_starget_port_id = 1,
  516. .get_starget_node_name = bfad_im_get_starget_node_name,
  517. .show_starget_node_name = 1,
  518. .get_starget_port_name = bfad_im_get_starget_port_name,
  519. .show_starget_port_name = 1,
  520. /* Host dynamic attribute */
  521. .get_host_port_id = bfad_im_get_host_port_id,
  522. .show_host_port_id = 1,
  523. /* Host fixed attributes */
  524. .show_host_node_name = 1,
  525. .show_host_port_name = 1,
  526. .show_host_supported_classes = 1,
  527. .show_host_supported_fc4s = 1,
  528. .show_host_supported_speeds = 1,
  529. .show_host_maxframe_size = 1,
  530. /* More host dynamic attributes */
  531. .show_host_port_type = 1,
  532. .get_host_port_type = bfad_im_get_host_port_type,
  533. .show_host_port_state = 1,
  534. .get_host_port_state = bfad_im_get_host_port_state,
  535. .show_host_active_fc4s = 1,
  536. .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
  537. .show_host_speed = 1,
  538. .get_host_speed = bfad_im_get_host_speed,
  539. .show_host_fabric_name = 1,
  540. .get_host_fabric_name = bfad_im_get_host_fabric_name,
  541. .show_host_symbolic_name = 1,
  542. /* Statistics */
  543. .get_fc_host_stats = bfad_im_get_stats,
  544. .reset_fc_host_stats = bfad_im_reset_stats,
  545. /* Allocation length for host specific data */
  546. .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
  547. /* Remote port fixed attributes */
  548. .show_rport_maxframe_size = 1,
  549. .show_rport_supported_classes = 1,
  550. .show_rport_dev_loss_tmo = 1,
  551. .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
  552. .issue_fc_host_lip = bfad_im_issue_fc_host_lip,
  553. .vport_create = bfad_im_vport_create,
  554. .vport_delete = bfad_im_vport_delete,
  555. .vport_disable = bfad_im_vport_disable,
  556. .set_vport_symbolic_name = bfad_im_vport_set_symbolic_name,
  557. .bsg_request = bfad_im_bsg_request,
  558. .bsg_timeout = bfad_im_bsg_timeout,
  559. };
  560. struct fc_function_template bfad_im_vport_fc_function_template = {
  561. /* Target dynamic attributes */
  562. .get_starget_port_id = bfad_im_get_starget_port_id,
  563. .show_starget_port_id = 1,
  564. .get_starget_node_name = bfad_im_get_starget_node_name,
  565. .show_starget_node_name = 1,
  566. .get_starget_port_name = bfad_im_get_starget_port_name,
  567. .show_starget_port_name = 1,
  568. /* Host dynamic attribute */
  569. .get_host_port_id = bfad_im_get_host_port_id,
  570. .show_host_port_id = 1,
  571. /* Host fixed attributes */
  572. .show_host_node_name = 1,
  573. .show_host_port_name = 1,
  574. .show_host_supported_classes = 1,
  575. .show_host_supported_fc4s = 1,
  576. .show_host_supported_speeds = 1,
  577. .show_host_maxframe_size = 1,
  578. /* More host dynamic attributes */
  579. .show_host_port_type = 1,
  580. .get_host_port_type = bfad_im_get_host_port_type,
  581. .show_host_port_state = 1,
  582. .get_host_port_state = bfad_im_get_host_port_state,
  583. .show_host_active_fc4s = 1,
  584. .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
  585. .show_host_speed = 1,
  586. .get_host_speed = bfad_im_get_host_speed,
  587. .show_host_fabric_name = 1,
  588. .get_host_fabric_name = bfad_im_get_host_fabric_name,
  589. .show_host_symbolic_name = 1,
  590. /* Statistics */
  591. .get_fc_host_stats = bfad_im_get_stats,
  592. .reset_fc_host_stats = bfad_im_reset_stats,
  593. /* Allocation length for host specific data */
  594. .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
  595. /* Remote port fixed attributes */
  596. .show_rport_maxframe_size = 1,
  597. .show_rport_supported_classes = 1,
  598. .show_rport_dev_loss_tmo = 1,
  599. .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
  600. };
  601. /*
  602. * Scsi_Host_attrs SCSI host attributes
  603. */
  604. static ssize_t
  605. bfad_im_serial_num_show(struct device *dev, struct device_attribute *attr,
  606. char *buf)
  607. {
  608. struct Scsi_Host *shost = class_to_shost(dev);
  609. struct bfad_im_port_s *im_port =
  610. (struct bfad_im_port_s *) shost->hostdata[0];
  611. struct bfad_s *bfad = im_port->bfad;
  612. char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
  613. bfa_get_adapter_serial_num(&bfad->bfa, serial_num);
  614. return snprintf(buf, PAGE_SIZE, "%s\n", serial_num);
  615. }
  616. static ssize_t
  617. bfad_im_model_show(struct device *dev, struct device_attribute *attr,
  618. char *buf)
  619. {
  620. struct Scsi_Host *shost = class_to_shost(dev);
  621. struct bfad_im_port_s *im_port =
  622. (struct bfad_im_port_s *) shost->hostdata[0];
  623. struct bfad_s *bfad = im_port->bfad;
  624. char model[BFA_ADAPTER_MODEL_NAME_LEN];
  625. bfa_get_adapter_model(&bfad->bfa, model);
  626. return snprintf(buf, PAGE_SIZE, "%s\n", model);
  627. }
  628. static ssize_t
  629. bfad_im_model_desc_show(struct device *dev, struct device_attribute *attr,
  630. char *buf)
  631. {
  632. struct Scsi_Host *shost = class_to_shost(dev);
  633. struct bfad_im_port_s *im_port =
  634. (struct bfad_im_port_s *) shost->hostdata[0];
  635. struct bfad_s *bfad = im_port->bfad;
  636. char model[BFA_ADAPTER_MODEL_NAME_LEN];
  637. char model_descr[BFA_ADAPTER_MODEL_DESCR_LEN];
  638. int nports = 0;
  639. bfa_get_adapter_model(&bfad->bfa, model);
  640. nports = bfa_get_nports(&bfad->bfa);
  641. if (!strcmp(model, "QLogic-425"))
  642. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  643. "QLogic BR-series 4Gbps PCIe dual port FC HBA");
  644. else if (!strcmp(model, "QLogic-825"))
  645. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  646. "QLogic BR-series 8Gbps PCIe dual port FC HBA");
  647. else if (!strcmp(model, "QLogic-42B"))
  648. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  649. "QLogic BR-series 4Gbps PCIe dual port FC HBA for HP");
  650. else if (!strcmp(model, "QLogic-82B"))
  651. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  652. "QLogic BR-series 8Gbps PCIe dual port FC HBA for HP");
  653. else if (!strcmp(model, "QLogic-1010"))
  654. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  655. "QLogic BR-series 10Gbps single port CNA");
  656. else if (!strcmp(model, "QLogic-1020"))
  657. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  658. "QLogic BR-series 10Gbps dual port CNA");
  659. else if (!strcmp(model, "QLogic-1007"))
  660. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  661. "QLogic BR-series 10Gbps CNA for IBM Blade Center");
  662. else if (!strcmp(model, "QLogic-415"))
  663. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  664. "QLogic BR-series 4Gbps PCIe single port FC HBA");
  665. else if (!strcmp(model, "QLogic-815"))
  666. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  667. "QLogic BR-series 8Gbps PCIe single port FC HBA");
  668. else if (!strcmp(model, "QLogic-41B"))
  669. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  670. "QLogic BR-series 4Gbps PCIe single port FC HBA for HP");
  671. else if (!strcmp(model, "QLogic-81B"))
  672. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  673. "QLogic BR-series 8Gbps PCIe single port FC HBA for HP");
  674. else if (!strcmp(model, "QLogic-804"))
  675. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  676. "QLogic BR-series 8Gbps FC HBA for HP Bladesystem C-class");
  677. else if (!strcmp(model, "QLogic-1741"))
  678. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  679. "QLogic BR-series 10Gbps CNA for Dell M-Series Blade Servers");
  680. else if (strstr(model, "QLogic-1860")) {
  681. if (nports == 1 && bfa_ioc_is_cna(&bfad->bfa.ioc))
  682. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  683. "QLogic BR-series 10Gbps single port CNA");
  684. else if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
  685. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  686. "QLogic BR-series 16Gbps PCIe single port FC HBA");
  687. else if (nports == 2 && bfa_ioc_is_cna(&bfad->bfa.ioc))
  688. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  689. "QLogic BR-series 10Gbps dual port CNA");
  690. else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
  691. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  692. "QLogic BR-series 16Gbps PCIe dual port FC HBA");
  693. } else if (!strcmp(model, "QLogic-1867")) {
  694. if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
  695. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  696. "QLogic BR-series 16Gbps PCIe single port FC HBA for IBM");
  697. else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
  698. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  699. "QLogic BR-series 16Gbps PCIe dual port FC HBA for IBM");
  700. } else
  701. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  702. "Invalid Model");
  703. return snprintf(buf, PAGE_SIZE, "%s\n", model_descr);
  704. }
  705. static ssize_t
  706. bfad_im_node_name_show(struct device *dev, struct device_attribute *attr,
  707. char *buf)
  708. {
  709. struct Scsi_Host *shost = class_to_shost(dev);
  710. struct bfad_im_port_s *im_port =
  711. (struct bfad_im_port_s *) shost->hostdata[0];
  712. struct bfad_port_s *port = im_port->port;
  713. u64 nwwn;
  714. nwwn = bfa_fcs_lport_get_nwwn(port->fcs_port);
  715. return snprintf(buf, PAGE_SIZE, "0x%llx\n", cpu_to_be64(nwwn));
  716. }
  717. static ssize_t
  718. bfad_im_symbolic_name_show(struct device *dev, struct device_attribute *attr,
  719. char *buf)
  720. {
  721. struct Scsi_Host *shost = class_to_shost(dev);
  722. struct bfad_im_port_s *im_port =
  723. (struct bfad_im_port_s *) shost->hostdata[0];
  724. struct bfad_s *bfad = im_port->bfad;
  725. struct bfa_lport_attr_s port_attr;
  726. char symname[BFA_SYMNAME_MAXLEN];
  727. bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
  728. strncpy(symname, port_attr.port_cfg.sym_name.symname,
  729. BFA_SYMNAME_MAXLEN);
  730. return snprintf(buf, PAGE_SIZE, "%s\n", symname);
  731. }
  732. static ssize_t
  733. bfad_im_hw_version_show(struct device *dev, struct device_attribute *attr,
  734. char *buf)
  735. {
  736. struct Scsi_Host *shost = class_to_shost(dev);
  737. struct bfad_im_port_s *im_port =
  738. (struct bfad_im_port_s *) shost->hostdata[0];
  739. struct bfad_s *bfad = im_port->bfad;
  740. char hw_ver[BFA_VERSION_LEN];
  741. bfa_get_pci_chip_rev(&bfad->bfa, hw_ver);
  742. return snprintf(buf, PAGE_SIZE, "%s\n", hw_ver);
  743. }
  744. static ssize_t
  745. bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr,
  746. char *buf)
  747. {
  748. return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_VERSION);
  749. }
  750. static ssize_t
  751. bfad_im_optionrom_version_show(struct device *dev,
  752. struct device_attribute *attr, char *buf)
  753. {
  754. struct Scsi_Host *shost = class_to_shost(dev);
  755. struct bfad_im_port_s *im_port =
  756. (struct bfad_im_port_s *) shost->hostdata[0];
  757. struct bfad_s *bfad = im_port->bfad;
  758. char optrom_ver[BFA_VERSION_LEN];
  759. bfa_get_adapter_optrom_ver(&bfad->bfa, optrom_ver);
  760. return snprintf(buf, PAGE_SIZE, "%s\n", optrom_ver);
  761. }
  762. static ssize_t
  763. bfad_im_fw_version_show(struct device *dev, struct device_attribute *attr,
  764. char *buf)
  765. {
  766. struct Scsi_Host *shost = class_to_shost(dev);
  767. struct bfad_im_port_s *im_port =
  768. (struct bfad_im_port_s *) shost->hostdata[0];
  769. struct bfad_s *bfad = im_port->bfad;
  770. char fw_ver[BFA_VERSION_LEN];
  771. bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
  772. return snprintf(buf, PAGE_SIZE, "%s\n", fw_ver);
  773. }
  774. static ssize_t
  775. bfad_im_num_of_ports_show(struct device *dev, struct device_attribute *attr,
  776. char *buf)
  777. {
  778. struct Scsi_Host *shost = class_to_shost(dev);
  779. struct bfad_im_port_s *im_port =
  780. (struct bfad_im_port_s *) shost->hostdata[0];
  781. struct bfad_s *bfad = im_port->bfad;
  782. return snprintf(buf, PAGE_SIZE, "%d\n",
  783. bfa_get_nports(&bfad->bfa));
  784. }
  785. static ssize_t
  786. bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr,
  787. char *buf)
  788. {
  789. return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_NAME);
  790. }
  791. static ssize_t
  792. bfad_im_num_of_discovered_ports_show(struct device *dev,
  793. struct device_attribute *attr, char *buf)
  794. {
  795. struct Scsi_Host *shost = class_to_shost(dev);
  796. struct bfad_im_port_s *im_port =
  797. (struct bfad_im_port_s *) shost->hostdata[0];
  798. struct bfad_port_s *port = im_port->port;
  799. struct bfad_s *bfad = im_port->bfad;
  800. int nrports = 2048;
  801. struct bfa_rport_qualifier_s *rports = NULL;
  802. unsigned long flags;
  803. rports = kzalloc(sizeof(struct bfa_rport_qualifier_s) * nrports,
  804. GFP_ATOMIC);
  805. if (rports == NULL)
  806. return snprintf(buf, PAGE_SIZE, "Failed\n");
  807. spin_lock_irqsave(&bfad->bfad_lock, flags);
  808. bfa_fcs_lport_get_rport_quals(port->fcs_port, rports, &nrports);
  809. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  810. kfree(rports);
  811. return snprintf(buf, PAGE_SIZE, "%d\n", nrports);
  812. }
  813. static DEVICE_ATTR(serial_number, S_IRUGO,
  814. bfad_im_serial_num_show, NULL);
  815. static DEVICE_ATTR(model, S_IRUGO, bfad_im_model_show, NULL);
  816. static DEVICE_ATTR(model_description, S_IRUGO,
  817. bfad_im_model_desc_show, NULL);
  818. static DEVICE_ATTR(node_name, S_IRUGO, bfad_im_node_name_show, NULL);
  819. static DEVICE_ATTR(symbolic_name, S_IRUGO,
  820. bfad_im_symbolic_name_show, NULL);
  821. static DEVICE_ATTR(hardware_version, S_IRUGO,
  822. bfad_im_hw_version_show, NULL);
  823. static DEVICE_ATTR(driver_version, S_IRUGO,
  824. bfad_im_drv_version_show, NULL);
  825. static DEVICE_ATTR(option_rom_version, S_IRUGO,
  826. bfad_im_optionrom_version_show, NULL);
  827. static DEVICE_ATTR(firmware_version, S_IRUGO,
  828. bfad_im_fw_version_show, NULL);
  829. static DEVICE_ATTR(number_of_ports, S_IRUGO,
  830. bfad_im_num_of_ports_show, NULL);
  831. static DEVICE_ATTR(driver_name, S_IRUGO, bfad_im_drv_name_show, NULL);
  832. static DEVICE_ATTR(number_of_discovered_ports, S_IRUGO,
  833. bfad_im_num_of_discovered_ports_show, NULL);
  834. struct device_attribute *bfad_im_host_attrs[] = {
  835. &dev_attr_serial_number,
  836. &dev_attr_model,
  837. &dev_attr_model_description,
  838. &dev_attr_node_name,
  839. &dev_attr_symbolic_name,
  840. &dev_attr_hardware_version,
  841. &dev_attr_driver_version,
  842. &dev_attr_option_rom_version,
  843. &dev_attr_firmware_version,
  844. &dev_attr_number_of_ports,
  845. &dev_attr_driver_name,
  846. &dev_attr_number_of_discovered_ports,
  847. NULL,
  848. };
  849. struct device_attribute *bfad_im_vport_attrs[] = {
  850. &dev_attr_serial_number,
  851. &dev_attr_model,
  852. &dev_attr_model_description,
  853. &dev_attr_node_name,
  854. &dev_attr_symbolic_name,
  855. &dev_attr_hardware_version,
  856. &dev_attr_driver_version,
  857. &dev_attr_option_rom_version,
  858. &dev_attr_firmware_version,
  859. &dev_attr_number_of_ports,
  860. &dev_attr_driver_name,
  861. &dev_attr_number_of_discovered_ports,
  862. NULL,
  863. };