zfcp_fsf.c 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2009
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include "zfcp_ext.h"
  12. #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
  13. #define ZFCP_REQ_NO_QTCB 0x00000008
  14. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  15. {
  16. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  17. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  18. "fsrth_1", NULL);
  19. }
  20. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  21. unsigned long timeout)
  22. {
  23. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  24. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  25. fsf_req->timer.expires = jiffies + timeout;
  26. add_timer(&fsf_req->timer);
  27. }
  28. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  29. {
  30. BUG_ON(!fsf_req->erp_action);
  31. fsf_req->timer.function = zfcp_erp_timeout_handler;
  32. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  33. fsf_req->timer.expires = jiffies + 30 * HZ;
  34. add_timer(&fsf_req->timer);
  35. }
  36. /* association between FSF command and FSF QTCB type */
  37. static u32 fsf_qtcb_type[] = {
  38. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  39. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  40. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  41. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  42. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  43. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  48. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  49. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  51. };
  52. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  53. {
  54. u16 subtable = table >> 16;
  55. u16 rule = table & 0xffff;
  56. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  57. if (subtable && subtable < ARRAY_SIZE(act_type))
  58. dev_warn(&adapter->ccw_device->dev,
  59. "Access denied according to ACT rule type %s, "
  60. "rule %d\n", act_type[subtable], rule);
  61. }
  62. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  63. struct zfcp_port *port)
  64. {
  65. struct fsf_qtcb_header *header = &req->qtcb->header;
  66. dev_warn(&req->adapter->ccw_device->dev,
  67. "Access denied to port 0x%016Lx\n",
  68. (unsigned long long)port->wwpn);
  69. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  70. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  71. zfcp_erp_port_access_denied(port, "fspad_1", req);
  72. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  73. }
  74. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  75. struct zfcp_unit *unit)
  76. {
  77. struct fsf_qtcb_header *header = &req->qtcb->header;
  78. dev_warn(&req->adapter->ccw_device->dev,
  79. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  80. (unsigned long long)unit->fcp_lun,
  81. (unsigned long long)unit->port->wwpn);
  82. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  83. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  84. zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
  85. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  86. }
  87. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  88. {
  89. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  90. "operational because of an unsupported FC class\n");
  91. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
  92. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  93. }
  94. /**
  95. * zfcp_fsf_req_free - free memory used by fsf request
  96. * @fsf_req: pointer to struct zfcp_fsf_req
  97. */
  98. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  99. {
  100. if (likely(req->pool)) {
  101. mempool_free(req, req->pool);
  102. return;
  103. }
  104. if (req->qtcb) {
  105. kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
  106. return;
  107. }
  108. }
  109. /**
  110. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  111. * @adapter: pointer to struct zfcp_adapter
  112. *
  113. * Never ever call this without shutting down the adapter first.
  114. * Otherwise the adapter would continue using and corrupting s390 storage.
  115. * Included BUG_ON() call to ensure this is done.
  116. * ERP is supposed to be the only user of this function.
  117. */
  118. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  119. {
  120. struct zfcp_fsf_req *req, *tmp;
  121. unsigned long flags;
  122. LIST_HEAD(remove_queue);
  123. unsigned int i;
  124. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  125. spin_lock_irqsave(&adapter->req_list_lock, flags);
  126. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  127. list_splice_init(&adapter->req_list[i], &remove_queue);
  128. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  129. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  130. list_del(&req->list);
  131. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  132. zfcp_fsf_req_complete(req);
  133. }
  134. }
  135. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  136. {
  137. struct fsf_status_read_buffer *sr_buf = req->data;
  138. struct zfcp_adapter *adapter = req->adapter;
  139. struct zfcp_port *port;
  140. int d_id = sr_buf->d_id & ZFCP_DID_MASK;
  141. unsigned long flags;
  142. read_lock_irqsave(&zfcp_data.config_lock, flags);
  143. list_for_each_entry(port, &adapter->port_list_head, list)
  144. if (port->d_id == d_id) {
  145. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  146. zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
  147. return;
  148. }
  149. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  150. }
  151. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
  152. struct fsf_link_down_info *link_down)
  153. {
  154. struct zfcp_adapter *adapter = req->adapter;
  155. unsigned long flags;
  156. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  157. return;
  158. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  159. read_lock_irqsave(&zfcp_data.config_lock, flags);
  160. zfcp_scsi_schedule_rports_block(adapter);
  161. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  162. if (!link_down)
  163. goto out;
  164. switch (link_down->error_code) {
  165. case FSF_PSQ_LINK_NO_LIGHT:
  166. dev_warn(&req->adapter->ccw_device->dev,
  167. "There is no light signal from the local "
  168. "fibre channel cable\n");
  169. break;
  170. case FSF_PSQ_LINK_WRAP_PLUG:
  171. dev_warn(&req->adapter->ccw_device->dev,
  172. "There is a wrap plug instead of a fibre "
  173. "channel cable\n");
  174. break;
  175. case FSF_PSQ_LINK_NO_FCP:
  176. dev_warn(&req->adapter->ccw_device->dev,
  177. "The adjacent fibre channel node does not "
  178. "support FCP\n");
  179. break;
  180. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  181. dev_warn(&req->adapter->ccw_device->dev,
  182. "The FCP device is suspended because of a "
  183. "firmware update\n");
  184. break;
  185. case FSF_PSQ_LINK_INVALID_WWPN:
  186. dev_warn(&req->adapter->ccw_device->dev,
  187. "The FCP device detected a WWPN that is "
  188. "duplicate or not valid\n");
  189. break;
  190. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  191. dev_warn(&req->adapter->ccw_device->dev,
  192. "The fibre channel fabric does not support NPIV\n");
  193. break;
  194. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  195. dev_warn(&req->adapter->ccw_device->dev,
  196. "The FCP adapter cannot support more NPIV ports\n");
  197. break;
  198. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  199. dev_warn(&req->adapter->ccw_device->dev,
  200. "The adjacent switch cannot support "
  201. "more NPIV ports\n");
  202. break;
  203. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  204. dev_warn(&req->adapter->ccw_device->dev,
  205. "The FCP adapter could not log in to the "
  206. "fibre channel fabric\n");
  207. break;
  208. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  209. dev_warn(&req->adapter->ccw_device->dev,
  210. "The WWPN assignment file on the FCP adapter "
  211. "has been damaged\n");
  212. break;
  213. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  214. dev_warn(&req->adapter->ccw_device->dev,
  215. "The mode table on the FCP adapter "
  216. "has been damaged\n");
  217. break;
  218. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  219. dev_warn(&req->adapter->ccw_device->dev,
  220. "All NPIV ports on the FCP adapter have "
  221. "been assigned\n");
  222. break;
  223. default:
  224. dev_warn(&req->adapter->ccw_device->dev,
  225. "The link between the FCP adapter and "
  226. "the FC fabric is down\n");
  227. }
  228. out:
  229. zfcp_erp_adapter_failed(adapter, id, req);
  230. }
  231. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  232. {
  233. struct fsf_status_read_buffer *sr_buf = req->data;
  234. struct fsf_link_down_info *ldi =
  235. (struct fsf_link_down_info *) &sr_buf->payload;
  236. switch (sr_buf->status_subtype) {
  237. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  238. zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
  239. break;
  240. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  241. zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
  242. break;
  243. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  244. zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
  245. };
  246. }
  247. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  248. {
  249. struct zfcp_adapter *adapter = req->adapter;
  250. struct fsf_status_read_buffer *sr_buf = req->data;
  251. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  252. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
  253. mempool_free(sr_buf, adapter->pool.data_status_read);
  254. zfcp_fsf_req_free(req);
  255. return;
  256. }
  257. zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
  258. switch (sr_buf->status_type) {
  259. case FSF_STATUS_READ_PORT_CLOSED:
  260. zfcp_fsf_status_read_port_closed(req);
  261. break;
  262. case FSF_STATUS_READ_INCOMING_ELS:
  263. zfcp_fc_incoming_els(req);
  264. break;
  265. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  266. break;
  267. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  268. dev_warn(&adapter->ccw_device->dev,
  269. "The error threshold for checksum statistics "
  270. "has been exceeded\n");
  271. zfcp_hba_dbf_event_berr(adapter, req);
  272. break;
  273. case FSF_STATUS_READ_LINK_DOWN:
  274. zfcp_fsf_status_read_link_down(req);
  275. break;
  276. case FSF_STATUS_READ_LINK_UP:
  277. dev_info(&adapter->ccw_device->dev,
  278. "The local link has been restored\n");
  279. /* All ports should be marked as ready to run again */
  280. zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
  281. ZFCP_STATUS_COMMON_RUNNING,
  282. ZFCP_SET);
  283. zfcp_erp_adapter_reopen(adapter,
  284. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  285. ZFCP_STATUS_COMMON_ERP_FAILED,
  286. "fssrh_2", req);
  287. break;
  288. case FSF_STATUS_READ_NOTIFICATION_LOST:
  289. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  290. zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
  291. req);
  292. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  293. schedule_work(&adapter->scan_work);
  294. break;
  295. case FSF_STATUS_READ_CFDC_UPDATED:
  296. zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
  297. break;
  298. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  299. adapter->adapter_features = sr_buf->payload.word[0];
  300. break;
  301. }
  302. mempool_free(sr_buf, adapter->pool.data_status_read);
  303. zfcp_fsf_req_free(req);
  304. atomic_inc(&adapter->stat_miss);
  305. queue_work(zfcp_data.work_queue, &adapter->stat_work);
  306. }
  307. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  308. {
  309. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  310. case FSF_SQ_FCP_RSP_AVAILABLE:
  311. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  312. case FSF_SQ_NO_RETRY_POSSIBLE:
  313. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  314. return;
  315. case FSF_SQ_COMMAND_ABORTED:
  316. req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  317. break;
  318. case FSF_SQ_NO_RECOM:
  319. dev_err(&req->adapter->ccw_device->dev,
  320. "The FCP adapter reported a problem "
  321. "that cannot be recovered\n");
  322. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
  323. break;
  324. }
  325. /* all non-return stats set FSFREQ_ERROR*/
  326. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  327. }
  328. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  329. {
  330. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  331. return;
  332. switch (req->qtcb->header.fsf_status) {
  333. case FSF_UNKNOWN_COMMAND:
  334. dev_err(&req->adapter->ccw_device->dev,
  335. "The FCP adapter does not recognize the command 0x%x\n",
  336. req->qtcb->header.fsf_command);
  337. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
  338. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  339. break;
  340. case FSF_ADAPTER_STATUS_AVAILABLE:
  341. zfcp_fsf_fsfstatus_qual_eval(req);
  342. break;
  343. }
  344. }
  345. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  346. {
  347. struct zfcp_adapter *adapter = req->adapter;
  348. struct fsf_qtcb *qtcb = req->qtcb;
  349. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  350. zfcp_hba_dbf_event_fsf_response(req);
  351. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  352. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  353. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  354. return;
  355. }
  356. switch (qtcb->prefix.prot_status) {
  357. case FSF_PROT_GOOD:
  358. case FSF_PROT_FSF_STATUS_PRESENTED:
  359. return;
  360. case FSF_PROT_QTCB_VERSION_ERROR:
  361. dev_err(&adapter->ccw_device->dev,
  362. "QTCB version 0x%x not supported by FCP adapter "
  363. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  364. psq->word[0], psq->word[1]);
  365. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
  366. break;
  367. case FSF_PROT_ERROR_STATE:
  368. case FSF_PROT_SEQ_NUMB_ERROR:
  369. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
  370. req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  371. break;
  372. case FSF_PROT_UNSUPP_QTCB_TYPE:
  373. dev_err(&adapter->ccw_device->dev,
  374. "The QTCB type is not supported by the FCP adapter\n");
  375. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
  376. break;
  377. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  378. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  379. &adapter->status);
  380. break;
  381. case FSF_PROT_DUPLICATE_REQUEST_ID:
  382. dev_err(&adapter->ccw_device->dev,
  383. "0x%Lx is an ambiguous request identifier\n",
  384. (unsigned long long)qtcb->bottom.support.req_handle);
  385. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
  386. break;
  387. case FSF_PROT_LINK_DOWN:
  388. zfcp_fsf_link_down_info_eval(req, "fspse_5",
  389. &psq->link_down_info);
  390. /* FIXME: reopening adapter now? better wait for link up */
  391. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
  392. break;
  393. case FSF_PROT_REEST_QUEUE:
  394. /* All ports should be marked as ready to run again */
  395. zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
  396. ZFCP_STATUS_COMMON_RUNNING,
  397. ZFCP_SET);
  398. zfcp_erp_adapter_reopen(adapter,
  399. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  400. ZFCP_STATUS_COMMON_ERP_FAILED,
  401. "fspse_8", req);
  402. break;
  403. default:
  404. dev_err(&adapter->ccw_device->dev,
  405. "0x%x is not a valid transfer protocol status\n",
  406. qtcb->prefix.prot_status);
  407. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
  408. }
  409. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  410. }
  411. /**
  412. * zfcp_fsf_req_complete - process completion of a FSF request
  413. * @fsf_req: The FSF request that has been completed.
  414. *
  415. * When a request has been completed either from the FCP adapter,
  416. * or it has been dismissed due to a queue shutdown, this function
  417. * is called to process the completion status and trigger further
  418. * events related to the FSF request.
  419. */
  420. void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  421. {
  422. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  423. zfcp_fsf_status_read_handler(req);
  424. return;
  425. }
  426. del_timer(&req->timer);
  427. zfcp_fsf_protstatus_eval(req);
  428. zfcp_fsf_fsfstatus_eval(req);
  429. req->handler(req);
  430. if (req->erp_action)
  431. zfcp_erp_notify(req->erp_action, 0);
  432. req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  433. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  434. zfcp_fsf_req_free(req);
  435. else
  436. /* notify initiator waiting for the requests completion */
  437. /*
  438. * FIXME: Race! We must not access fsf_req here as it might have been
  439. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  440. * flag. It's an improbable case. But, we have the same paranoia for
  441. * the cleanup flag already.
  442. * Might better be handled using complete()?
  443. * (setting the flag and doing wakeup ought to be atomic
  444. * with regard to checking the flag as long as waitqueue is
  445. * part of the to be released structure)
  446. */
  447. wake_up(&req->completion_wq);
  448. }
  449. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  450. {
  451. struct fsf_qtcb_bottom_config *bottom;
  452. struct zfcp_adapter *adapter = req->adapter;
  453. struct Scsi_Host *shost = adapter->scsi_host;
  454. bottom = &req->qtcb->bottom.config;
  455. if (req->data)
  456. memcpy(req->data, bottom, sizeof(*bottom));
  457. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  458. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  459. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  460. fc_host_speed(shost) = bottom->fc_link_speed;
  461. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  462. adapter->hydra_version = bottom->adapter_type;
  463. adapter->timer_ticks = bottom->timer_interval;
  464. if (fc_host_permanent_port_name(shost) == -1)
  465. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  466. switch (bottom->fc_topology) {
  467. case FSF_TOPO_P2P:
  468. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  469. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  470. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  471. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  472. break;
  473. case FSF_TOPO_FABRIC:
  474. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  475. break;
  476. case FSF_TOPO_AL:
  477. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  478. /* fall through */
  479. default:
  480. dev_err(&adapter->ccw_device->dev,
  481. "Unknown or unsupported arbitrated loop "
  482. "fibre channel topology detected\n");
  483. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  484. return -EIO;
  485. }
  486. return 0;
  487. }
  488. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  489. {
  490. struct zfcp_adapter *adapter = req->adapter;
  491. struct fsf_qtcb *qtcb = req->qtcb;
  492. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  493. struct Scsi_Host *shost = adapter->scsi_host;
  494. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  495. return;
  496. adapter->fsf_lic_version = bottom->lic_version;
  497. adapter->adapter_features = bottom->adapter_features;
  498. adapter->connection_features = bottom->connection_features;
  499. adapter->peer_wwpn = 0;
  500. adapter->peer_wwnn = 0;
  501. adapter->peer_d_id = 0;
  502. switch (qtcb->header.fsf_status) {
  503. case FSF_GOOD:
  504. if (zfcp_fsf_exchange_config_evaluate(req))
  505. return;
  506. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  507. dev_err(&adapter->ccw_device->dev,
  508. "FCP adapter maximum QTCB size (%d bytes) "
  509. "is too small\n",
  510. bottom->max_qtcb_size);
  511. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  512. return;
  513. }
  514. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  515. &adapter->status);
  516. break;
  517. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  518. fc_host_node_name(shost) = 0;
  519. fc_host_port_name(shost) = 0;
  520. fc_host_port_id(shost) = 0;
  521. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  522. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  523. adapter->hydra_version = 0;
  524. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  525. &adapter->status);
  526. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  527. &qtcb->header.fsf_status_qual.link_down_info);
  528. break;
  529. default:
  530. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  531. return;
  532. }
  533. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  534. adapter->hardware_version = bottom->hardware_version;
  535. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  536. min(FC_SERIAL_NUMBER_SIZE, 17));
  537. EBCASC(fc_host_serial_number(shost),
  538. min(FC_SERIAL_NUMBER_SIZE, 17));
  539. }
  540. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  541. dev_err(&adapter->ccw_device->dev,
  542. "The FCP adapter only supports newer "
  543. "control block versions\n");
  544. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  545. return;
  546. }
  547. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  548. dev_err(&adapter->ccw_device->dev,
  549. "The FCP adapter only supports older "
  550. "control block versions\n");
  551. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  552. }
  553. }
  554. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  555. {
  556. struct zfcp_adapter *adapter = req->adapter;
  557. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  558. struct Scsi_Host *shost = adapter->scsi_host;
  559. if (req->data)
  560. memcpy(req->data, bottom, sizeof(*bottom));
  561. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  562. fc_host_permanent_port_name(shost) = bottom->wwpn;
  563. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  564. } else
  565. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  566. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  567. fc_host_supported_speeds(shost) = bottom->supported_speed;
  568. }
  569. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  570. {
  571. struct fsf_qtcb *qtcb = req->qtcb;
  572. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  573. return;
  574. switch (qtcb->header.fsf_status) {
  575. case FSF_GOOD:
  576. zfcp_fsf_exchange_port_evaluate(req);
  577. break;
  578. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  579. zfcp_fsf_exchange_port_evaluate(req);
  580. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  581. &qtcb->header.fsf_status_qual.link_down_info);
  582. break;
  583. }
  584. }
  585. static int zfcp_fsf_sbal_check(struct zfcp_adapter *adapter)
  586. {
  587. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  588. spin_lock_bh(&adapter->req_q_lock);
  589. if (atomic_read(&req_q->count))
  590. return 1;
  591. spin_unlock_bh(&adapter->req_q_lock);
  592. return 0;
  593. }
  594. static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
  595. {
  596. long ret;
  597. spin_unlock_bh(&adapter->req_q_lock);
  598. ret = wait_event_interruptible_timeout(adapter->request_wq,
  599. zfcp_fsf_sbal_check(adapter), 5 * HZ);
  600. if (ret > 0)
  601. return 0;
  602. if (!ret)
  603. atomic_inc(&adapter->qdio_outb_full);
  604. spin_lock_bh(&adapter->req_q_lock);
  605. return -EIO;
  606. }
  607. static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
  608. {
  609. struct zfcp_fsf_req *req;
  610. req = mempool_alloc(pool, GFP_ATOMIC);
  611. if (!req)
  612. return NULL;
  613. memset(req, 0, sizeof(*req));
  614. req->pool = pool;
  615. return req;
  616. }
  617. static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
  618. {
  619. struct zfcp_fsf_req_qtcb *qtcb;
  620. if (likely(pool))
  621. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  622. else
  623. qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  624. GFP_ATOMIC);
  625. if (unlikely(!qtcb))
  626. return NULL;
  627. memset(qtcb, 0, sizeof(*qtcb));
  628. qtcb->fsf_req.qtcb = &qtcb->qtcb;
  629. qtcb->fsf_req.pool = pool;
  630. return &qtcb->fsf_req;
  631. }
  632. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
  633. u32 fsf_cmd, int req_flags,
  634. mempool_t *pool)
  635. {
  636. struct qdio_buffer_element *sbale;
  637. struct zfcp_fsf_req *req;
  638. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  639. if (req_flags & ZFCP_REQ_NO_QTCB)
  640. req = zfcp_fsf_alloc_noqtcb(pool);
  641. else
  642. req = zfcp_fsf_alloc_qtcb(pool);
  643. if (unlikely(!req))
  644. return ERR_PTR(-EIO);
  645. if (adapter->req_no == 0)
  646. adapter->req_no++;
  647. INIT_LIST_HEAD(&req->list);
  648. init_timer(&req->timer);
  649. init_waitqueue_head(&req->completion_wq);
  650. req->adapter = adapter;
  651. req->fsf_command = fsf_cmd;
  652. req->req_id = adapter->req_no;
  653. req->sbal_number = 1;
  654. req->sbal_first = req_q->first;
  655. req->sbal_last = req_q->first;
  656. req->sbale_curr = 1;
  657. sbale = zfcp_qdio_sbale_req(req);
  658. sbale[0].addr = (void *) req->req_id;
  659. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  660. if (likely(req->qtcb)) {
  661. req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
  662. req->qtcb->prefix.req_id = req->req_id;
  663. req->qtcb->prefix.ulp_info = 26;
  664. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  665. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  666. req->qtcb->header.req_handle = req->req_id;
  667. req->qtcb->header.fsf_command = req->fsf_command;
  668. req->seq_no = adapter->fsf_req_seq_no;
  669. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  670. sbale[1].addr = (void *) req->qtcb;
  671. sbale[1].length = sizeof(struct fsf_qtcb);
  672. }
  673. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  674. zfcp_fsf_req_free(req);
  675. return ERR_PTR(-EIO);
  676. }
  677. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
  678. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  679. return req;
  680. }
  681. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  682. {
  683. struct zfcp_adapter *adapter = req->adapter;
  684. unsigned long flags;
  685. int idx;
  686. int with_qtcb = (req->qtcb != NULL);
  687. /* put allocated FSF request into hash table */
  688. spin_lock_irqsave(&adapter->req_list_lock, flags);
  689. idx = zfcp_reqlist_hash(req->req_id);
  690. list_add_tail(&req->list, &adapter->req_list[idx]);
  691. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  692. req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
  693. req->issued = get_clock();
  694. if (zfcp_qdio_send(req)) {
  695. del_timer(&req->timer);
  696. spin_lock_irqsave(&adapter->req_list_lock, flags);
  697. /* lookup request again, list might have changed */
  698. if (zfcp_reqlist_find_safe(adapter, req))
  699. zfcp_reqlist_remove(adapter, req);
  700. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  701. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  702. return -EIO;
  703. }
  704. /* Don't increase for unsolicited status */
  705. if (with_qtcb)
  706. adapter->fsf_req_seq_no++;
  707. adapter->req_no++;
  708. return 0;
  709. }
  710. /**
  711. * zfcp_fsf_status_read - send status read request
  712. * @adapter: pointer to struct zfcp_adapter
  713. * @req_flags: request flags
  714. * Returns: 0 on success, ERROR otherwise
  715. */
  716. int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
  717. {
  718. struct zfcp_fsf_req *req;
  719. struct fsf_status_read_buffer *sr_buf;
  720. struct qdio_buffer_element *sbale;
  721. int retval = -EIO;
  722. spin_lock_bh(&adapter->req_q_lock);
  723. if (zfcp_fsf_req_sbal_get(adapter))
  724. goto out;
  725. req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  726. ZFCP_REQ_NO_QTCB,
  727. adapter->pool.fsf_req_status_read);
  728. if (IS_ERR(req)) {
  729. retval = PTR_ERR(req);
  730. goto out;
  731. }
  732. sbale = zfcp_qdio_sbale_req(req);
  733. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  734. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  735. req->sbale_curr = 2;
  736. sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  737. if (!sr_buf) {
  738. retval = -ENOMEM;
  739. goto failed_buf;
  740. }
  741. memset(sr_buf, 0, sizeof(*sr_buf));
  742. req->data = sr_buf;
  743. sbale = zfcp_qdio_sbale_curr(req);
  744. sbale->addr = (void *) sr_buf;
  745. sbale->length = sizeof(*sr_buf);
  746. retval = zfcp_fsf_req_send(req);
  747. if (retval)
  748. goto failed_req_send;
  749. goto out;
  750. failed_req_send:
  751. mempool_free(sr_buf, adapter->pool.data_status_read);
  752. failed_buf:
  753. zfcp_fsf_req_free(req);
  754. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  755. out:
  756. spin_unlock_bh(&adapter->req_q_lock);
  757. return retval;
  758. }
  759. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  760. {
  761. struct zfcp_unit *unit = req->data;
  762. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  763. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  764. return;
  765. switch (req->qtcb->header.fsf_status) {
  766. case FSF_PORT_HANDLE_NOT_VALID:
  767. if (fsq->word[0] == fsq->word[1]) {
  768. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  769. "fsafch1", req);
  770. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  771. }
  772. break;
  773. case FSF_LUN_HANDLE_NOT_VALID:
  774. if (fsq->word[0] == fsq->word[1]) {
  775. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  776. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  777. }
  778. break;
  779. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  780. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  781. break;
  782. case FSF_PORT_BOXED:
  783. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  784. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  785. ZFCP_STATUS_FSFREQ_RETRY;
  786. break;
  787. case FSF_LUN_BOXED:
  788. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  789. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  790. ZFCP_STATUS_FSFREQ_RETRY;
  791. break;
  792. case FSF_ADAPTER_STATUS_AVAILABLE:
  793. switch (fsq->word[0]) {
  794. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  795. zfcp_test_link(unit->port);
  796. /* fall through */
  797. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  798. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  799. break;
  800. }
  801. break;
  802. case FSF_GOOD:
  803. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  804. break;
  805. }
  806. }
  807. /**
  808. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  809. * @old_req_id: unsigned long
  810. * @unit: pointer to struct zfcp_unit
  811. * Returns: pointer to struct zfcp_fsf_req
  812. */
  813. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  814. struct zfcp_unit *unit)
  815. {
  816. struct qdio_buffer_element *sbale;
  817. struct zfcp_fsf_req *req = NULL;
  818. struct zfcp_adapter *adapter = unit->port->adapter;
  819. spin_lock_bh(&adapter->req_q_lock);
  820. if (zfcp_fsf_req_sbal_get(adapter))
  821. goto out;
  822. req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  823. 0, adapter->pool.fsf_req_abort);
  824. if (IS_ERR(req)) {
  825. req = NULL;
  826. goto out;
  827. }
  828. if (unlikely(!(atomic_read(&unit->status) &
  829. ZFCP_STATUS_COMMON_UNBLOCKED)))
  830. goto out_error_free;
  831. sbale = zfcp_qdio_sbale_req(req);
  832. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  833. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  834. req->data = unit;
  835. req->handler = zfcp_fsf_abort_fcp_command_handler;
  836. req->qtcb->header.lun_handle = unit->handle;
  837. req->qtcb->header.port_handle = unit->port->handle;
  838. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  839. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  840. if (!zfcp_fsf_req_send(req))
  841. goto out;
  842. out_error_free:
  843. zfcp_fsf_req_free(req);
  844. req = NULL;
  845. out:
  846. spin_unlock_bh(&adapter->req_q_lock);
  847. return req;
  848. }
  849. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  850. {
  851. struct zfcp_adapter *adapter = req->adapter;
  852. struct zfcp_send_ct *send_ct = req->data;
  853. struct fsf_qtcb_header *header = &req->qtcb->header;
  854. send_ct->status = -EINVAL;
  855. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  856. goto skip_fsfstatus;
  857. switch (header->fsf_status) {
  858. case FSF_GOOD:
  859. zfcp_san_dbf_event_ct_response(req);
  860. send_ct->status = 0;
  861. break;
  862. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  863. zfcp_fsf_class_not_supp(req);
  864. break;
  865. case FSF_ADAPTER_STATUS_AVAILABLE:
  866. switch (header->fsf_status_qual.word[0]){
  867. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  868. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  869. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  870. break;
  871. }
  872. break;
  873. case FSF_ACCESS_DENIED:
  874. break;
  875. case FSF_PORT_BOXED:
  876. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  877. ZFCP_STATUS_FSFREQ_RETRY;
  878. break;
  879. case FSF_PORT_HANDLE_NOT_VALID:
  880. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  881. /* fall through */
  882. case FSF_GENERIC_COMMAND_REJECTED:
  883. case FSF_PAYLOAD_SIZE_MISMATCH:
  884. case FSF_REQUEST_SIZE_TOO_LARGE:
  885. case FSF_RESPONSE_SIZE_TOO_LARGE:
  886. case FSF_SBAL_MISMATCH:
  887. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  888. break;
  889. }
  890. skip_fsfstatus:
  891. if (send_ct->handler)
  892. send_ct->handler(send_ct->handler_data);
  893. }
  894. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  895. struct scatterlist *sg_req,
  896. struct scatterlist *sg_resp,
  897. int max_sbals)
  898. {
  899. struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req);
  900. u32 feat = req->adapter->adapter_features;
  901. int bytes;
  902. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  903. if (sg_req->length > PAGE_SIZE || sg_resp->length > PAGE_SIZE ||
  904. !sg_is_last(sg_req) || !sg_is_last(sg_resp))
  905. return -EOPNOTSUPP;
  906. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  907. sbale[2].addr = sg_virt(sg_req);
  908. sbale[2].length = sg_req->length;
  909. sbale[3].addr = sg_virt(sg_resp);
  910. sbale[3].length = sg_resp->length;
  911. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  912. return 0;
  913. }
  914. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  915. sg_req, max_sbals);
  916. if (bytes <= 0)
  917. return -ENOMEM;
  918. req->qtcb->bottom.support.req_buf_length = bytes;
  919. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  920. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  921. sg_resp, max_sbals);
  922. if (bytes <= 0)
  923. return -ENOMEM;
  924. req->qtcb->bottom.support.resp_buf_length = bytes;
  925. return 0;
  926. }
  927. /**
  928. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  929. * @ct: pointer to struct zfcp_send_ct with data for request
  930. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  931. * @erp_action: if non-null the Generic Service request sent within ERP
  932. */
  933. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  934. struct zfcp_erp_action *erp_action)
  935. {
  936. struct zfcp_wka_port *wka_port = ct->wka_port;
  937. struct zfcp_adapter *adapter = wka_port->adapter;
  938. struct zfcp_fsf_req *req;
  939. int ret = -EIO;
  940. spin_lock_bh(&adapter->req_q_lock);
  941. if (zfcp_fsf_req_sbal_get(adapter))
  942. goto out;
  943. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  944. ZFCP_REQ_AUTO_CLEANUP, pool);
  945. if (IS_ERR(req)) {
  946. ret = PTR_ERR(req);
  947. goto out;
  948. }
  949. ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
  950. FSF_MAX_SBALS_PER_REQ);
  951. if (ret)
  952. goto failed_send;
  953. req->handler = zfcp_fsf_send_ct_handler;
  954. req->qtcb->header.port_handle = wka_port->handle;
  955. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  956. req->qtcb->bottom.support.timeout = ct->timeout;
  957. req->data = ct;
  958. zfcp_san_dbf_event_ct_request(req);
  959. if (erp_action) {
  960. erp_action->fsf_req = req;
  961. req->erp_action = erp_action;
  962. zfcp_fsf_start_erp_timer(req);
  963. } else
  964. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  965. ret = zfcp_fsf_req_send(req);
  966. if (ret)
  967. goto failed_send;
  968. goto out;
  969. failed_send:
  970. zfcp_fsf_req_free(req);
  971. if (erp_action)
  972. erp_action->fsf_req = NULL;
  973. out:
  974. spin_unlock_bh(&adapter->req_q_lock);
  975. return ret;
  976. }
  977. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  978. {
  979. struct zfcp_send_els *send_els = req->data;
  980. struct zfcp_port *port = send_els->port;
  981. struct fsf_qtcb_header *header = &req->qtcb->header;
  982. send_els->status = -EINVAL;
  983. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  984. goto skip_fsfstatus;
  985. switch (header->fsf_status) {
  986. case FSF_GOOD:
  987. zfcp_san_dbf_event_els_response(req);
  988. send_els->status = 0;
  989. break;
  990. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  991. zfcp_fsf_class_not_supp(req);
  992. break;
  993. case FSF_ADAPTER_STATUS_AVAILABLE:
  994. switch (header->fsf_status_qual.word[0]){
  995. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  996. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  997. zfcp_test_link(port);
  998. /*fall through */
  999. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1000. case FSF_SQ_RETRY_IF_POSSIBLE:
  1001. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1002. break;
  1003. }
  1004. break;
  1005. case FSF_ELS_COMMAND_REJECTED:
  1006. case FSF_PAYLOAD_SIZE_MISMATCH:
  1007. case FSF_REQUEST_SIZE_TOO_LARGE:
  1008. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1009. break;
  1010. case FSF_ACCESS_DENIED:
  1011. if (port)
  1012. zfcp_fsf_access_denied_port(req, port);
  1013. break;
  1014. case FSF_SBAL_MISMATCH:
  1015. /* should never occure, avoided in zfcp_fsf_send_els */
  1016. /* fall through */
  1017. default:
  1018. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1019. break;
  1020. }
  1021. skip_fsfstatus:
  1022. if (send_els->handler)
  1023. send_els->handler(send_els->handler_data);
  1024. }
  1025. /**
  1026. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1027. * @els: pointer to struct zfcp_send_els with data for the command
  1028. */
  1029. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1030. {
  1031. struct zfcp_fsf_req *req;
  1032. struct zfcp_adapter *adapter = els->adapter;
  1033. struct fsf_qtcb_bottom_support *bottom;
  1034. int ret = -EIO;
  1035. spin_lock_bh(&adapter->req_q_lock);
  1036. if (zfcp_fsf_req_sbal_get(adapter))
  1037. goto out;
  1038. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1039. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1040. if (IS_ERR(req)) {
  1041. ret = PTR_ERR(req);
  1042. goto out;
  1043. }
  1044. ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
  1045. if (ret)
  1046. goto failed_send;
  1047. bottom = &req->qtcb->bottom.support;
  1048. req->handler = zfcp_fsf_send_els_handler;
  1049. bottom->d_id = els->d_id;
  1050. bottom->service_class = FSF_CLASS_3;
  1051. bottom->timeout = 2 * R_A_TOV;
  1052. req->data = els;
  1053. zfcp_san_dbf_event_els_request(req);
  1054. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1055. ret = zfcp_fsf_req_send(req);
  1056. if (ret)
  1057. goto failed_send;
  1058. goto out;
  1059. failed_send:
  1060. zfcp_fsf_req_free(req);
  1061. out:
  1062. spin_unlock_bh(&adapter->req_q_lock);
  1063. return ret;
  1064. }
  1065. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1066. {
  1067. struct qdio_buffer_element *sbale;
  1068. struct zfcp_fsf_req *req;
  1069. struct zfcp_adapter *adapter = erp_action->adapter;
  1070. int retval = -EIO;
  1071. spin_lock_bh(&adapter->req_q_lock);
  1072. if (zfcp_fsf_req_sbal_get(adapter))
  1073. goto out;
  1074. req = zfcp_fsf_req_create(adapter,
  1075. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1076. ZFCP_REQ_AUTO_CLEANUP,
  1077. adapter->pool.fsf_req_erp);
  1078. if (IS_ERR(req)) {
  1079. retval = PTR_ERR(req);
  1080. goto out;
  1081. }
  1082. sbale = zfcp_qdio_sbale_req(req);
  1083. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1084. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1085. req->qtcb->bottom.config.feature_selection =
  1086. FSF_FEATURE_CFDC |
  1087. FSF_FEATURE_LUN_SHARING |
  1088. FSF_FEATURE_NOTIFICATION_LOST |
  1089. FSF_FEATURE_UPDATE_ALERT;
  1090. req->erp_action = erp_action;
  1091. req->handler = zfcp_fsf_exchange_config_data_handler;
  1092. erp_action->fsf_req = req;
  1093. zfcp_fsf_start_erp_timer(req);
  1094. retval = zfcp_fsf_req_send(req);
  1095. if (retval) {
  1096. zfcp_fsf_req_free(req);
  1097. erp_action->fsf_req = NULL;
  1098. }
  1099. out:
  1100. spin_unlock_bh(&adapter->req_q_lock);
  1101. return retval;
  1102. }
  1103. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1104. struct fsf_qtcb_bottom_config *data)
  1105. {
  1106. struct qdio_buffer_element *sbale;
  1107. struct zfcp_fsf_req *req = NULL;
  1108. int retval = -EIO;
  1109. spin_lock_bh(&adapter->req_q_lock);
  1110. if (zfcp_fsf_req_sbal_get(adapter))
  1111. goto out_unlock;
  1112. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1113. 0, NULL);
  1114. if (IS_ERR(req)) {
  1115. retval = PTR_ERR(req);
  1116. goto out_unlock;
  1117. }
  1118. sbale = zfcp_qdio_sbale_req(req);
  1119. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1120. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1121. req->handler = zfcp_fsf_exchange_config_data_handler;
  1122. req->qtcb->bottom.config.feature_selection =
  1123. FSF_FEATURE_CFDC |
  1124. FSF_FEATURE_LUN_SHARING |
  1125. FSF_FEATURE_NOTIFICATION_LOST |
  1126. FSF_FEATURE_UPDATE_ALERT;
  1127. if (data)
  1128. req->data = data;
  1129. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1130. retval = zfcp_fsf_req_send(req);
  1131. spin_unlock_bh(&adapter->req_q_lock);
  1132. if (!retval)
  1133. wait_event(req->completion_wq,
  1134. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1135. zfcp_fsf_req_free(req);
  1136. return retval;
  1137. out_unlock:
  1138. spin_unlock_bh(&adapter->req_q_lock);
  1139. return retval;
  1140. }
  1141. /**
  1142. * zfcp_fsf_exchange_port_data - request information about local port
  1143. * @erp_action: ERP action for the adapter for which port data is requested
  1144. * Returns: 0 on success, error otherwise
  1145. */
  1146. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1147. {
  1148. struct qdio_buffer_element *sbale;
  1149. struct zfcp_fsf_req *req;
  1150. struct zfcp_adapter *adapter = erp_action->adapter;
  1151. int retval = -EIO;
  1152. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1153. return -EOPNOTSUPP;
  1154. spin_lock_bh(&adapter->req_q_lock);
  1155. if (zfcp_fsf_req_sbal_get(adapter))
  1156. goto out;
  1157. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1158. ZFCP_REQ_AUTO_CLEANUP,
  1159. adapter->pool.fsf_req_erp);
  1160. if (IS_ERR(req)) {
  1161. retval = PTR_ERR(req);
  1162. goto out;
  1163. }
  1164. sbale = zfcp_qdio_sbale_req(req);
  1165. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1166. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1167. req->handler = zfcp_fsf_exchange_port_data_handler;
  1168. req->erp_action = erp_action;
  1169. erp_action->fsf_req = req;
  1170. zfcp_fsf_start_erp_timer(req);
  1171. retval = zfcp_fsf_req_send(req);
  1172. if (retval) {
  1173. zfcp_fsf_req_free(req);
  1174. erp_action->fsf_req = NULL;
  1175. }
  1176. out:
  1177. spin_unlock_bh(&adapter->req_q_lock);
  1178. return retval;
  1179. }
  1180. /**
  1181. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1182. * @adapter: pointer to struct zfcp_adapter
  1183. * @data: pointer to struct fsf_qtcb_bottom_port
  1184. * Returns: 0 on success, error otherwise
  1185. */
  1186. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1187. struct fsf_qtcb_bottom_port *data)
  1188. {
  1189. struct qdio_buffer_element *sbale;
  1190. struct zfcp_fsf_req *req = NULL;
  1191. int retval = -EIO;
  1192. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1193. return -EOPNOTSUPP;
  1194. spin_lock_bh(&adapter->req_q_lock);
  1195. if (zfcp_fsf_req_sbal_get(adapter))
  1196. goto out_unlock;
  1197. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1198. NULL);
  1199. if (IS_ERR(req)) {
  1200. retval = PTR_ERR(req);
  1201. goto out_unlock;
  1202. }
  1203. if (data)
  1204. req->data = data;
  1205. sbale = zfcp_qdio_sbale_req(req);
  1206. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1207. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1208. req->handler = zfcp_fsf_exchange_port_data_handler;
  1209. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1210. retval = zfcp_fsf_req_send(req);
  1211. spin_unlock_bh(&adapter->req_q_lock);
  1212. if (!retval)
  1213. wait_event(req->completion_wq,
  1214. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1215. zfcp_fsf_req_free(req);
  1216. return retval;
  1217. out_unlock:
  1218. spin_unlock_bh(&adapter->req_q_lock);
  1219. return retval;
  1220. }
  1221. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1222. {
  1223. struct zfcp_port *port = req->data;
  1224. struct fsf_qtcb_header *header = &req->qtcb->header;
  1225. struct fsf_plogi *plogi;
  1226. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1227. goto out;
  1228. switch (header->fsf_status) {
  1229. case FSF_PORT_ALREADY_OPEN:
  1230. break;
  1231. case FSF_ACCESS_DENIED:
  1232. zfcp_fsf_access_denied_port(req, port);
  1233. break;
  1234. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1235. dev_warn(&req->adapter->ccw_device->dev,
  1236. "Not enough FCP adapter resources to open "
  1237. "remote port 0x%016Lx\n",
  1238. (unsigned long long)port->wwpn);
  1239. zfcp_erp_port_failed(port, "fsoph_1", req);
  1240. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1241. break;
  1242. case FSF_ADAPTER_STATUS_AVAILABLE:
  1243. switch (header->fsf_status_qual.word[0]) {
  1244. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1245. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1246. case FSF_SQ_NO_RETRY_POSSIBLE:
  1247. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1248. break;
  1249. }
  1250. break;
  1251. case FSF_GOOD:
  1252. port->handle = header->port_handle;
  1253. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1254. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1255. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1256. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1257. &port->status);
  1258. /* check whether D_ID has changed during open */
  1259. /*
  1260. * FIXME: This check is not airtight, as the FCP channel does
  1261. * not monitor closures of target port connections caused on
  1262. * the remote side. Thus, they might miss out on invalidating
  1263. * locally cached WWPNs (and other N_Port parameters) of gone
  1264. * target ports. So, our heroic attempt to make things safe
  1265. * could be undermined by 'open port' response data tagged with
  1266. * obsolete WWPNs. Another reason to monitor potential
  1267. * connection closures ourself at least (by interpreting
  1268. * incoming ELS' and unsolicited status). It just crosses my
  1269. * mind that one should be able to cross-check by means of
  1270. * another GID_PN straight after a port has been opened.
  1271. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1272. */
  1273. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1274. if (req->qtcb->bottom.support.els1_length >=
  1275. FSF_PLOGI_MIN_LEN) {
  1276. if (plogi->serv_param.wwpn != port->wwpn)
  1277. port->d_id = 0;
  1278. else {
  1279. port->wwnn = plogi->serv_param.wwnn;
  1280. zfcp_fc_plogi_evaluate(port, plogi);
  1281. }
  1282. }
  1283. break;
  1284. case FSF_UNKNOWN_OP_SUBTYPE:
  1285. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1286. break;
  1287. }
  1288. out:
  1289. zfcp_port_put(port);
  1290. }
  1291. /**
  1292. * zfcp_fsf_open_port - create and send open port request
  1293. * @erp_action: pointer to struct zfcp_erp_action
  1294. * Returns: 0 on success, error otherwise
  1295. */
  1296. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1297. {
  1298. struct qdio_buffer_element *sbale;
  1299. struct zfcp_adapter *adapter = erp_action->adapter;
  1300. struct zfcp_fsf_req *req;
  1301. struct zfcp_port *port = erp_action->port;
  1302. int retval = -EIO;
  1303. spin_lock_bh(&adapter->req_q_lock);
  1304. if (zfcp_fsf_req_sbal_get(adapter))
  1305. goto out;
  1306. req = zfcp_fsf_req_create(adapter,
  1307. FSF_QTCB_OPEN_PORT_WITH_DID,
  1308. ZFCP_REQ_AUTO_CLEANUP,
  1309. adapter->pool.fsf_req_erp);
  1310. if (IS_ERR(req)) {
  1311. retval = PTR_ERR(req);
  1312. goto out;
  1313. }
  1314. sbale = zfcp_qdio_sbale_req(req);
  1315. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1316. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1317. req->handler = zfcp_fsf_open_port_handler;
  1318. req->qtcb->bottom.support.d_id = port->d_id;
  1319. req->data = port;
  1320. req->erp_action = erp_action;
  1321. erp_action->fsf_req = req;
  1322. zfcp_port_get(port);
  1323. zfcp_fsf_start_erp_timer(req);
  1324. retval = zfcp_fsf_req_send(req);
  1325. if (retval) {
  1326. zfcp_fsf_req_free(req);
  1327. erp_action->fsf_req = NULL;
  1328. zfcp_port_put(port);
  1329. }
  1330. out:
  1331. spin_unlock_bh(&adapter->req_q_lock);
  1332. return retval;
  1333. }
  1334. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1335. {
  1336. struct zfcp_port *port = req->data;
  1337. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1338. return;
  1339. switch (req->qtcb->header.fsf_status) {
  1340. case FSF_PORT_HANDLE_NOT_VALID:
  1341. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1342. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1343. break;
  1344. case FSF_ADAPTER_STATUS_AVAILABLE:
  1345. break;
  1346. case FSF_GOOD:
  1347. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1348. ZFCP_STATUS_COMMON_OPEN,
  1349. ZFCP_CLEAR);
  1350. break;
  1351. }
  1352. }
  1353. /**
  1354. * zfcp_fsf_close_port - create and send close port request
  1355. * @erp_action: pointer to struct zfcp_erp_action
  1356. * Returns: 0 on success, error otherwise
  1357. */
  1358. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1359. {
  1360. struct qdio_buffer_element *sbale;
  1361. struct zfcp_adapter *adapter = erp_action->adapter;
  1362. struct zfcp_fsf_req *req;
  1363. int retval = -EIO;
  1364. spin_lock_bh(&adapter->req_q_lock);
  1365. if (zfcp_fsf_req_sbal_get(adapter))
  1366. goto out;
  1367. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1368. ZFCP_REQ_AUTO_CLEANUP,
  1369. adapter->pool.fsf_req_erp);
  1370. if (IS_ERR(req)) {
  1371. retval = PTR_ERR(req);
  1372. goto out;
  1373. }
  1374. sbale = zfcp_qdio_sbale_req(req);
  1375. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1376. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1377. req->handler = zfcp_fsf_close_port_handler;
  1378. req->data = erp_action->port;
  1379. req->erp_action = erp_action;
  1380. req->qtcb->header.port_handle = erp_action->port->handle;
  1381. erp_action->fsf_req = req;
  1382. zfcp_fsf_start_erp_timer(req);
  1383. retval = zfcp_fsf_req_send(req);
  1384. if (retval) {
  1385. zfcp_fsf_req_free(req);
  1386. erp_action->fsf_req = NULL;
  1387. }
  1388. out:
  1389. spin_unlock_bh(&adapter->req_q_lock);
  1390. return retval;
  1391. }
  1392. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1393. {
  1394. struct zfcp_wka_port *wka_port = req->data;
  1395. struct fsf_qtcb_header *header = &req->qtcb->header;
  1396. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1397. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1398. goto out;
  1399. }
  1400. switch (header->fsf_status) {
  1401. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1402. dev_warn(&req->adapter->ccw_device->dev,
  1403. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1404. /* fall through */
  1405. case FSF_ADAPTER_STATUS_AVAILABLE:
  1406. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1407. /* fall through */
  1408. case FSF_ACCESS_DENIED:
  1409. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1410. break;
  1411. case FSF_PORT_ALREADY_OPEN:
  1412. break;
  1413. case FSF_GOOD:
  1414. wka_port->handle = header->port_handle;
  1415. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1416. }
  1417. out:
  1418. wake_up(&wka_port->completion_wq);
  1419. }
  1420. /**
  1421. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1422. * @wka_port: pointer to struct zfcp_wka_port
  1423. * Returns: 0 on success, error otherwise
  1424. */
  1425. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1426. {
  1427. struct qdio_buffer_element *sbale;
  1428. struct zfcp_adapter *adapter = wka_port->adapter;
  1429. struct zfcp_fsf_req *req;
  1430. int retval = -EIO;
  1431. spin_lock_bh(&adapter->req_q_lock);
  1432. if (zfcp_fsf_req_sbal_get(adapter))
  1433. goto out;
  1434. req = zfcp_fsf_req_create(adapter,
  1435. FSF_QTCB_OPEN_PORT_WITH_DID,
  1436. ZFCP_REQ_AUTO_CLEANUP,
  1437. adapter->pool.fsf_req_erp);
  1438. if (unlikely(IS_ERR(req))) {
  1439. retval = PTR_ERR(req);
  1440. goto out;
  1441. }
  1442. sbale = zfcp_qdio_sbale_req(req);
  1443. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1444. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1445. req->handler = zfcp_fsf_open_wka_port_handler;
  1446. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1447. req->data = wka_port;
  1448. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1449. retval = zfcp_fsf_req_send(req);
  1450. if (retval)
  1451. zfcp_fsf_req_free(req);
  1452. out:
  1453. spin_unlock_bh(&adapter->req_q_lock);
  1454. return retval;
  1455. }
  1456. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1457. {
  1458. struct zfcp_wka_port *wka_port = req->data;
  1459. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1460. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1461. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1462. }
  1463. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1464. wake_up(&wka_port->completion_wq);
  1465. }
  1466. /**
  1467. * zfcp_fsf_close_wka_port - create and send close wka port request
  1468. * @erp_action: pointer to struct zfcp_erp_action
  1469. * Returns: 0 on success, error otherwise
  1470. */
  1471. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1472. {
  1473. struct qdio_buffer_element *sbale;
  1474. struct zfcp_adapter *adapter = wka_port->adapter;
  1475. struct zfcp_fsf_req *req;
  1476. int retval = -EIO;
  1477. spin_lock_bh(&adapter->req_q_lock);
  1478. if (zfcp_fsf_req_sbal_get(adapter))
  1479. goto out;
  1480. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1481. ZFCP_REQ_AUTO_CLEANUP,
  1482. adapter->pool.fsf_req_erp);
  1483. if (unlikely(IS_ERR(req))) {
  1484. retval = PTR_ERR(req);
  1485. goto out;
  1486. }
  1487. sbale = zfcp_qdio_sbale_req(req);
  1488. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1489. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1490. req->handler = zfcp_fsf_close_wka_port_handler;
  1491. req->data = wka_port;
  1492. req->qtcb->header.port_handle = wka_port->handle;
  1493. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1494. retval = zfcp_fsf_req_send(req);
  1495. if (retval)
  1496. zfcp_fsf_req_free(req);
  1497. out:
  1498. spin_unlock_bh(&adapter->req_q_lock);
  1499. return retval;
  1500. }
  1501. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1502. {
  1503. struct zfcp_port *port = req->data;
  1504. struct fsf_qtcb_header *header = &req->qtcb->header;
  1505. struct zfcp_unit *unit;
  1506. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1507. return;
  1508. switch (header->fsf_status) {
  1509. case FSF_PORT_HANDLE_NOT_VALID:
  1510. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1511. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1512. break;
  1513. case FSF_ACCESS_DENIED:
  1514. zfcp_fsf_access_denied_port(req, port);
  1515. break;
  1516. case FSF_PORT_BOXED:
  1517. /* can't use generic zfcp_erp_modify_port_status because
  1518. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1519. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1520. list_for_each_entry(unit, &port->unit_list_head, list)
  1521. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1522. &unit->status);
  1523. zfcp_erp_port_boxed(port, "fscpph2", req);
  1524. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1525. ZFCP_STATUS_FSFREQ_RETRY;
  1526. break;
  1527. case FSF_ADAPTER_STATUS_AVAILABLE:
  1528. switch (header->fsf_status_qual.word[0]) {
  1529. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1530. /* fall through */
  1531. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1532. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1533. break;
  1534. }
  1535. break;
  1536. case FSF_GOOD:
  1537. /* can't use generic zfcp_erp_modify_port_status because
  1538. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1539. */
  1540. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1541. list_for_each_entry(unit, &port->unit_list_head, list)
  1542. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1543. &unit->status);
  1544. break;
  1545. }
  1546. }
  1547. /**
  1548. * zfcp_fsf_close_physical_port - close physical port
  1549. * @erp_action: pointer to struct zfcp_erp_action
  1550. * Returns: 0 on success
  1551. */
  1552. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1553. {
  1554. struct qdio_buffer_element *sbale;
  1555. struct zfcp_adapter *adapter = erp_action->adapter;
  1556. struct zfcp_fsf_req *req;
  1557. int retval = -EIO;
  1558. spin_lock_bh(&adapter->req_q_lock);
  1559. if (zfcp_fsf_req_sbal_get(adapter))
  1560. goto out;
  1561. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1562. ZFCP_REQ_AUTO_CLEANUP,
  1563. adapter->pool.fsf_req_erp);
  1564. if (IS_ERR(req)) {
  1565. retval = PTR_ERR(req);
  1566. goto out;
  1567. }
  1568. sbale = zfcp_qdio_sbale_req(req);
  1569. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1570. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1571. req->data = erp_action->port;
  1572. req->qtcb->header.port_handle = erp_action->port->handle;
  1573. req->erp_action = erp_action;
  1574. req->handler = zfcp_fsf_close_physical_port_handler;
  1575. erp_action->fsf_req = req;
  1576. zfcp_fsf_start_erp_timer(req);
  1577. retval = zfcp_fsf_req_send(req);
  1578. if (retval) {
  1579. zfcp_fsf_req_free(req);
  1580. erp_action->fsf_req = NULL;
  1581. }
  1582. out:
  1583. spin_unlock_bh(&adapter->req_q_lock);
  1584. return retval;
  1585. }
  1586. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1587. {
  1588. struct zfcp_adapter *adapter = req->adapter;
  1589. struct zfcp_unit *unit = req->data;
  1590. struct fsf_qtcb_header *header = &req->qtcb->header;
  1591. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1592. struct fsf_queue_designator *queue_designator =
  1593. &header->fsf_status_qual.fsf_queue_designator;
  1594. int exclusive, readwrite;
  1595. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1596. return;
  1597. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1598. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1599. ZFCP_STATUS_UNIT_SHARED |
  1600. ZFCP_STATUS_UNIT_READONLY,
  1601. &unit->status);
  1602. switch (header->fsf_status) {
  1603. case FSF_PORT_HANDLE_NOT_VALID:
  1604. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1605. /* fall through */
  1606. case FSF_LUN_ALREADY_OPEN:
  1607. break;
  1608. case FSF_ACCESS_DENIED:
  1609. zfcp_fsf_access_denied_unit(req, unit);
  1610. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1611. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1612. break;
  1613. case FSF_PORT_BOXED:
  1614. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1615. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1616. ZFCP_STATUS_FSFREQ_RETRY;
  1617. break;
  1618. case FSF_LUN_SHARING_VIOLATION:
  1619. if (header->fsf_status_qual.word[0])
  1620. dev_warn(&adapter->ccw_device->dev,
  1621. "LUN 0x%Lx on port 0x%Lx is already in "
  1622. "use by CSS%d, MIF Image ID %x\n",
  1623. (unsigned long long)unit->fcp_lun,
  1624. (unsigned long long)unit->port->wwpn,
  1625. queue_designator->cssid,
  1626. queue_designator->hla);
  1627. else
  1628. zfcp_act_eval_err(adapter,
  1629. header->fsf_status_qual.word[2]);
  1630. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1631. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1632. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1633. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1634. break;
  1635. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1636. dev_warn(&adapter->ccw_device->dev,
  1637. "No handle is available for LUN "
  1638. "0x%016Lx on port 0x%016Lx\n",
  1639. (unsigned long long)unit->fcp_lun,
  1640. (unsigned long long)unit->port->wwpn);
  1641. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1642. /* fall through */
  1643. case FSF_INVALID_COMMAND_OPTION:
  1644. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1645. break;
  1646. case FSF_ADAPTER_STATUS_AVAILABLE:
  1647. switch (header->fsf_status_qual.word[0]) {
  1648. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1649. zfcp_test_link(unit->port);
  1650. /* fall through */
  1651. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1652. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1653. break;
  1654. }
  1655. break;
  1656. case FSF_GOOD:
  1657. unit->handle = header->lun_handle;
  1658. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1659. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1660. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1661. !zfcp_ccw_priv_sch(adapter)) {
  1662. exclusive = (bottom->lun_access_info &
  1663. FSF_UNIT_ACCESS_EXCLUSIVE);
  1664. readwrite = (bottom->lun_access_info &
  1665. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1666. if (!exclusive)
  1667. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1668. &unit->status);
  1669. if (!readwrite) {
  1670. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1671. &unit->status);
  1672. dev_info(&adapter->ccw_device->dev,
  1673. "SCSI device at LUN 0x%016Lx on port "
  1674. "0x%016Lx opened read-only\n",
  1675. (unsigned long long)unit->fcp_lun,
  1676. (unsigned long long)unit->port->wwpn);
  1677. }
  1678. if (exclusive && !readwrite) {
  1679. dev_err(&adapter->ccw_device->dev,
  1680. "Exclusive read-only access not "
  1681. "supported (unit 0x%016Lx, "
  1682. "port 0x%016Lx)\n",
  1683. (unsigned long long)unit->fcp_lun,
  1684. (unsigned long long)unit->port->wwpn);
  1685. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1686. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1687. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1688. } else if (!exclusive && readwrite) {
  1689. dev_err(&adapter->ccw_device->dev,
  1690. "Shared read-write access not "
  1691. "supported (unit 0x%016Lx, port "
  1692. "0x%016Lx)\n",
  1693. (unsigned long long)unit->fcp_lun,
  1694. (unsigned long long)unit->port->wwpn);
  1695. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1696. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1697. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1698. }
  1699. }
  1700. break;
  1701. }
  1702. }
  1703. /**
  1704. * zfcp_fsf_open_unit - open unit
  1705. * @erp_action: pointer to struct zfcp_erp_action
  1706. * Returns: 0 on success, error otherwise
  1707. */
  1708. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1709. {
  1710. struct qdio_buffer_element *sbale;
  1711. struct zfcp_adapter *adapter = erp_action->adapter;
  1712. struct zfcp_fsf_req *req;
  1713. int retval = -EIO;
  1714. spin_lock_bh(&adapter->req_q_lock);
  1715. if (zfcp_fsf_req_sbal_get(adapter))
  1716. goto out;
  1717. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1718. ZFCP_REQ_AUTO_CLEANUP,
  1719. adapter->pool.fsf_req_erp);
  1720. if (IS_ERR(req)) {
  1721. retval = PTR_ERR(req);
  1722. goto out;
  1723. }
  1724. sbale = zfcp_qdio_sbale_req(req);
  1725. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1726. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1727. req->qtcb->header.port_handle = erp_action->port->handle;
  1728. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1729. req->handler = zfcp_fsf_open_unit_handler;
  1730. req->data = erp_action->unit;
  1731. req->erp_action = erp_action;
  1732. erp_action->fsf_req = req;
  1733. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1734. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1735. zfcp_fsf_start_erp_timer(req);
  1736. retval = zfcp_fsf_req_send(req);
  1737. if (retval) {
  1738. zfcp_fsf_req_free(req);
  1739. erp_action->fsf_req = NULL;
  1740. }
  1741. out:
  1742. spin_unlock_bh(&adapter->req_q_lock);
  1743. return retval;
  1744. }
  1745. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1746. {
  1747. struct zfcp_unit *unit = req->data;
  1748. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1749. return;
  1750. switch (req->qtcb->header.fsf_status) {
  1751. case FSF_PORT_HANDLE_NOT_VALID:
  1752. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1753. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1754. break;
  1755. case FSF_LUN_HANDLE_NOT_VALID:
  1756. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1757. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1758. break;
  1759. case FSF_PORT_BOXED:
  1760. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1761. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1762. ZFCP_STATUS_FSFREQ_RETRY;
  1763. break;
  1764. case FSF_ADAPTER_STATUS_AVAILABLE:
  1765. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1766. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1767. zfcp_test_link(unit->port);
  1768. /* fall through */
  1769. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1770. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1771. break;
  1772. }
  1773. break;
  1774. case FSF_GOOD:
  1775. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1776. break;
  1777. }
  1778. }
  1779. /**
  1780. * zfcp_fsf_close_unit - close zfcp unit
  1781. * @erp_action: pointer to struct zfcp_unit
  1782. * Returns: 0 on success, error otherwise
  1783. */
  1784. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1785. {
  1786. struct qdio_buffer_element *sbale;
  1787. struct zfcp_adapter *adapter = erp_action->adapter;
  1788. struct zfcp_fsf_req *req;
  1789. int retval = -EIO;
  1790. spin_lock_bh(&adapter->req_q_lock);
  1791. if (zfcp_fsf_req_sbal_get(adapter))
  1792. goto out;
  1793. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1794. ZFCP_REQ_AUTO_CLEANUP,
  1795. adapter->pool.fsf_req_erp);
  1796. if (IS_ERR(req)) {
  1797. retval = PTR_ERR(req);
  1798. goto out;
  1799. }
  1800. sbale = zfcp_qdio_sbale_req(req);
  1801. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1802. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1803. req->qtcb->header.port_handle = erp_action->port->handle;
  1804. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1805. req->handler = zfcp_fsf_close_unit_handler;
  1806. req->data = erp_action->unit;
  1807. req->erp_action = erp_action;
  1808. erp_action->fsf_req = req;
  1809. zfcp_fsf_start_erp_timer(req);
  1810. retval = zfcp_fsf_req_send(req);
  1811. if (retval) {
  1812. zfcp_fsf_req_free(req);
  1813. erp_action->fsf_req = NULL;
  1814. }
  1815. out:
  1816. spin_unlock_bh(&adapter->req_q_lock);
  1817. return retval;
  1818. }
  1819. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1820. {
  1821. lat_rec->sum += lat;
  1822. lat_rec->min = min(lat_rec->min, lat);
  1823. lat_rec->max = max(lat_rec->max, lat);
  1824. }
  1825. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1826. {
  1827. struct fsf_qual_latency_info *lat_inf;
  1828. struct latency_cont *lat;
  1829. struct zfcp_unit *unit = req->unit;
  1830. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1831. switch (req->qtcb->bottom.io.data_direction) {
  1832. case FSF_DATADIR_READ:
  1833. lat = &unit->latencies.read;
  1834. break;
  1835. case FSF_DATADIR_WRITE:
  1836. lat = &unit->latencies.write;
  1837. break;
  1838. case FSF_DATADIR_CMND:
  1839. lat = &unit->latencies.cmd;
  1840. break;
  1841. default:
  1842. return;
  1843. }
  1844. spin_lock(&unit->latencies.lock);
  1845. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1846. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1847. lat->counter++;
  1848. spin_unlock(&unit->latencies.lock);
  1849. }
  1850. #ifdef CONFIG_BLK_DEV_IO_TRACE
  1851. static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1852. {
  1853. struct fsf_qual_latency_info *lat_inf;
  1854. struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  1855. struct request *req = scsi_cmnd->request;
  1856. struct zfcp_blk_drv_data trace;
  1857. int ticks = fsf_req->adapter->timer_ticks;
  1858. trace.flags = 0;
  1859. trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1860. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1861. trace.flags |= ZFCP_BLK_LAT_VALID;
  1862. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  1863. trace.channel_lat = lat_inf->channel_lat * ticks;
  1864. trace.fabric_lat = lat_inf->fabric_lat * ticks;
  1865. }
  1866. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1867. trace.flags |= ZFCP_BLK_REQ_ERROR;
  1868. trace.inb_usage = fsf_req->qdio_inb_usage;
  1869. trace.outb_usage = fsf_req->qdio_outb_usage;
  1870. blk_add_driver_data(req->q, req, &trace, sizeof(trace));
  1871. }
  1872. #else
  1873. static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1874. {
  1875. }
  1876. #endif
  1877. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1878. {
  1879. struct scsi_cmnd *scpnt;
  1880. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1881. &(req->qtcb->bottom.io.fcp_rsp);
  1882. u32 sns_len;
  1883. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1884. unsigned long flags;
  1885. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1886. scpnt = req->data;
  1887. if (unlikely(!scpnt)) {
  1888. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1889. return;
  1890. }
  1891. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1892. set_host_byte(scpnt, DID_SOFT_ERROR);
  1893. goto skip_fsfstatus;
  1894. }
  1895. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1896. set_host_byte(scpnt, DID_ERROR);
  1897. goto skip_fsfstatus;
  1898. }
  1899. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1900. scpnt->result |= fcp_rsp_iu->scsi_status;
  1901. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1902. zfcp_fsf_req_latency(req);
  1903. zfcp_fsf_trace_latency(req);
  1904. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1905. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1906. set_host_byte(scpnt, DID_OK);
  1907. else {
  1908. set_host_byte(scpnt, DID_ERROR);
  1909. goto skip_fsfstatus;
  1910. }
  1911. }
  1912. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1913. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1914. fcp_rsp_iu->fcp_rsp_len;
  1915. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1916. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1917. memcpy(scpnt->sense_buffer,
  1918. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1919. }
  1920. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1921. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1922. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1923. scpnt->underflow)
  1924. set_host_byte(scpnt, DID_ERROR);
  1925. }
  1926. skip_fsfstatus:
  1927. if (scpnt->result != 0)
  1928. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1929. else if (scpnt->retries > 0)
  1930. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1931. else
  1932. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1933. scpnt->host_scribble = NULL;
  1934. (scpnt->scsi_done) (scpnt);
  1935. /*
  1936. * We must hold this lock until scsi_done has been called.
  1937. * Otherwise we may call scsi_done after abort regarding this
  1938. * command has completed.
  1939. * Note: scsi_done must not block!
  1940. */
  1941. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1942. }
  1943. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1944. {
  1945. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1946. &(req->qtcb->bottom.io.fcp_rsp);
  1947. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1948. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1949. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1950. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1951. }
  1952. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1953. {
  1954. struct zfcp_unit *unit;
  1955. struct fsf_qtcb_header *header = &req->qtcb->header;
  1956. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1957. unit = req->data;
  1958. else
  1959. unit = req->unit;
  1960. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1961. goto skip_fsfstatus;
  1962. switch (header->fsf_status) {
  1963. case FSF_HANDLE_MISMATCH:
  1964. case FSF_PORT_HANDLE_NOT_VALID:
  1965. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1966. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1967. break;
  1968. case FSF_FCPLUN_NOT_VALID:
  1969. case FSF_LUN_HANDLE_NOT_VALID:
  1970. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1971. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1972. break;
  1973. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1974. zfcp_fsf_class_not_supp(req);
  1975. break;
  1976. case FSF_ACCESS_DENIED:
  1977. zfcp_fsf_access_denied_unit(req, unit);
  1978. break;
  1979. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1980. dev_err(&req->adapter->ccw_device->dev,
  1981. "Incorrect direction %d, unit 0x%016Lx on port "
  1982. "0x%016Lx closed\n",
  1983. req->qtcb->bottom.io.data_direction,
  1984. (unsigned long long)unit->fcp_lun,
  1985. (unsigned long long)unit->port->wwpn);
  1986. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1987. req);
  1988. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1989. break;
  1990. case FSF_CMND_LENGTH_NOT_VALID:
  1991. dev_err(&req->adapter->ccw_device->dev,
  1992. "Incorrect CDB length %d, unit 0x%016Lx on "
  1993. "port 0x%016Lx closed\n",
  1994. req->qtcb->bottom.io.fcp_cmnd_length,
  1995. (unsigned long long)unit->fcp_lun,
  1996. (unsigned long long)unit->port->wwpn);
  1997. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1998. req);
  1999. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2000. break;
  2001. case FSF_PORT_BOXED:
  2002. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  2003. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2004. ZFCP_STATUS_FSFREQ_RETRY;
  2005. break;
  2006. case FSF_LUN_BOXED:
  2007. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  2008. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2009. ZFCP_STATUS_FSFREQ_RETRY;
  2010. break;
  2011. case FSF_ADAPTER_STATUS_AVAILABLE:
  2012. if (header->fsf_status_qual.word[0] ==
  2013. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  2014. zfcp_test_link(unit->port);
  2015. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2016. break;
  2017. }
  2018. skip_fsfstatus:
  2019. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  2020. zfcp_fsf_send_fcp_ctm_handler(req);
  2021. else {
  2022. zfcp_fsf_send_fcp_command_task_handler(req);
  2023. req->unit = NULL;
  2024. zfcp_unit_put(unit);
  2025. }
  2026. }
  2027. static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
  2028. {
  2029. u32 *fcp_dl_ptr;
  2030. /*
  2031. * fcp_dl_addr = start address of fcp_cmnd structure +
  2032. * size of fixed part + size of dynamically sized add_dcp_cdb field
  2033. * SEE FCP-2 documentation
  2034. */
  2035. fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
  2036. (fcp_cmd->add_fcp_cdb_length << 2));
  2037. *fcp_dl_ptr = fcp_dl;
  2038. }
  2039. /**
  2040. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  2041. * @unit: unit where command is sent to
  2042. * @scsi_cmnd: scsi command to be sent
  2043. */
  2044. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  2045. struct scsi_cmnd *scsi_cmnd)
  2046. {
  2047. struct zfcp_fsf_req *req;
  2048. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2049. unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
  2050. int real_bytes, retval = -EIO;
  2051. struct zfcp_adapter *adapter = unit->port->adapter;
  2052. if (unlikely(!(atomic_read(&unit->status) &
  2053. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2054. return -EBUSY;
  2055. spin_lock(&adapter->req_q_lock);
  2056. if (atomic_read(&adapter->req_q.count) <= 0) {
  2057. atomic_inc(&adapter->qdio_outb_full);
  2058. goto out;
  2059. }
  2060. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND,
  2061. ZFCP_REQ_AUTO_CLEANUP,
  2062. adapter->pool.fsf_req_scsi);
  2063. if (IS_ERR(req)) {
  2064. retval = PTR_ERR(req);
  2065. goto out;
  2066. }
  2067. zfcp_unit_get(unit);
  2068. req->unit = unit;
  2069. req->data = scsi_cmnd;
  2070. req->handler = zfcp_fsf_send_fcp_command_handler;
  2071. req->qtcb->header.lun_handle = unit->handle;
  2072. req->qtcb->header.port_handle = unit->port->handle;
  2073. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2074. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2075. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2076. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2077. /*
  2078. * set depending on data direction:
  2079. * data direction bits in SBALE (SB Type)
  2080. * data direction bits in QTCB
  2081. * data direction bits in FCP_CMND IU
  2082. */
  2083. switch (scsi_cmnd->sc_data_direction) {
  2084. case DMA_NONE:
  2085. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2086. break;
  2087. case DMA_FROM_DEVICE:
  2088. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2089. fcp_cmnd_iu->rddata = 1;
  2090. break;
  2091. case DMA_TO_DEVICE:
  2092. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2093. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2094. fcp_cmnd_iu->wddata = 1;
  2095. break;
  2096. case DMA_BIDIRECTIONAL:
  2097. goto failed_scsi_cmnd;
  2098. }
  2099. if (likely((scsi_cmnd->device->simple_tags) ||
  2100. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2101. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2102. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2103. else
  2104. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2105. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2106. fcp_cmnd_iu->add_fcp_cdb_length =
  2107. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2108. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2109. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2110. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
  2111. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2112. scsi_sglist(scsi_cmnd),
  2113. FSF_MAX_SBALS_PER_REQ);
  2114. if (unlikely(real_bytes < 0)) {
  2115. if (req->sbal_number >= FSF_MAX_SBALS_PER_REQ) {
  2116. dev_err(&adapter->ccw_device->dev,
  2117. "Oversize data package, unit 0x%016Lx "
  2118. "on port 0x%016Lx closed\n",
  2119. (unsigned long long)unit->fcp_lun,
  2120. (unsigned long long)unit->port->wwpn);
  2121. zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
  2122. retval = -EINVAL;
  2123. }
  2124. goto failed_scsi_cmnd;
  2125. }
  2126. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2127. retval = zfcp_fsf_req_send(req);
  2128. if (unlikely(retval))
  2129. goto failed_scsi_cmnd;
  2130. goto out;
  2131. failed_scsi_cmnd:
  2132. zfcp_unit_put(unit);
  2133. zfcp_fsf_req_free(req);
  2134. scsi_cmnd->host_scribble = NULL;
  2135. out:
  2136. spin_unlock(&adapter->req_q_lock);
  2137. return retval;
  2138. }
  2139. /**
  2140. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2141. * @unit: pointer to struct zfcp_unit
  2142. * @tm_flags: unsigned byte for task management flags
  2143. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2144. */
  2145. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  2146. {
  2147. struct qdio_buffer_element *sbale;
  2148. struct zfcp_fsf_req *req = NULL;
  2149. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2150. struct zfcp_adapter *adapter = unit->port->adapter;
  2151. if (unlikely(!(atomic_read(&unit->status) &
  2152. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2153. return NULL;
  2154. spin_lock_bh(&adapter->req_q_lock);
  2155. if (zfcp_fsf_req_sbal_get(adapter))
  2156. goto out;
  2157. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, 0,
  2158. adapter->pool.fsf_req_scsi);
  2159. if (IS_ERR(req)) {
  2160. req = NULL;
  2161. goto out;
  2162. }
  2163. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2164. req->data = unit;
  2165. req->handler = zfcp_fsf_send_fcp_command_handler;
  2166. req->qtcb->header.lun_handle = unit->handle;
  2167. req->qtcb->header.port_handle = unit->port->handle;
  2168. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2169. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2170. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2171. sizeof(u32);
  2172. sbale = zfcp_qdio_sbale_req(req);
  2173. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2174. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2175. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2176. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2177. fcp_cmnd_iu->task_management_flags = tm_flags;
  2178. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2179. if (!zfcp_fsf_req_send(req))
  2180. goto out;
  2181. zfcp_fsf_req_free(req);
  2182. req = NULL;
  2183. out:
  2184. spin_unlock_bh(&adapter->req_q_lock);
  2185. return req;
  2186. }
  2187. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2188. {
  2189. }
  2190. /**
  2191. * zfcp_fsf_control_file - control file upload/download
  2192. * @adapter: pointer to struct zfcp_adapter
  2193. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2194. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2195. */
  2196. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2197. struct zfcp_fsf_cfdc *fsf_cfdc)
  2198. {
  2199. struct qdio_buffer_element *sbale;
  2200. struct zfcp_fsf_req *req = NULL;
  2201. struct fsf_qtcb_bottom_support *bottom;
  2202. int direction, retval = -EIO, bytes;
  2203. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2204. return ERR_PTR(-EOPNOTSUPP);
  2205. switch (fsf_cfdc->command) {
  2206. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2207. direction = SBAL_FLAGS0_TYPE_WRITE;
  2208. break;
  2209. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2210. direction = SBAL_FLAGS0_TYPE_READ;
  2211. break;
  2212. default:
  2213. return ERR_PTR(-EINVAL);
  2214. }
  2215. spin_lock_bh(&adapter->req_q_lock);
  2216. if (zfcp_fsf_req_sbal_get(adapter))
  2217. goto out;
  2218. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2219. if (IS_ERR(req)) {
  2220. retval = -EPERM;
  2221. goto out;
  2222. }
  2223. req->handler = zfcp_fsf_control_file_handler;
  2224. sbale = zfcp_qdio_sbale_req(req);
  2225. sbale[0].flags |= direction;
  2226. bottom = &req->qtcb->bottom.support;
  2227. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2228. bottom->option = fsf_cfdc->option;
  2229. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2230. FSF_MAX_SBALS_PER_REQ);
  2231. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2232. retval = -ENOMEM;
  2233. zfcp_fsf_req_free(req);
  2234. goto out;
  2235. }
  2236. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2237. retval = zfcp_fsf_req_send(req);
  2238. out:
  2239. spin_unlock_bh(&adapter->req_q_lock);
  2240. if (!retval) {
  2241. wait_event(req->completion_wq,
  2242. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2243. return req;
  2244. }
  2245. return ERR_PTR(retval);
  2246. }