zfcp_fsf.c 74 KB

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